How can I change the JSXIdentifier node? #2456
-
My mdx content is below and want to render it in react native:
It throws: Then I try to use Is there a way to change a JSXIdentifier node? Thanks for helping. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
First I would propose some alternatives:
If you still want to do a custom transform, you can use the ESTree nodes. You first need to find import { walk } from 'estree-walker'
import { visit } from 'unist-util-visit'
/** @type {import('mdast').Root} */
let root;
visit(root, 'mdxjsEsm', (mdxjsEsm) => {
const program = mdxjsEsm.data?.program
if (!program) {
return
}
walk(program, {
enter(node) {
switch (node.type) {
case 'JSXIdentifier': {
// Handle your node
}
}
}
})
}) |
Beta Was this translation helpful? Give feedback.
Adding on.
MDX both with
components
and withProvider
works like JSX does.Custom components (those starting with an uppercase letter) can be customized, built-ins (components starting with a lowercase letter) cannot.