MDX Deep Dive
Using React and JavaScript
You can use React components and JavaScript in MDX files.
Using React components
You can import and use components from jsx and tsx files created in the project directory.
You can also use React components declared within the MDX file. Use export
in variable declarations within the MDX file, as described below.
Using JavasSript variables
JavaScript variables can be declared and used in MDX files.
Declare Variables.
Variables used throughout the page are declared in the MDX file using export
.
Referencing Variables.
Declared variables are referenced by enclosing them in {}
.
The result is as follows.
The time the page was opened is
The content enclosed in
{}
is evaluated as a JSX node and must be either a string, boolean, number, null, undefined, or React component.