Building with Codegen
React and JSX
GraphSitter exposes several React and JSX-specific APIs for working with modern React codebases.
Key APIs include:
- Function.is_jsx - Check if a function contains JSX elements
- Class.jsx_elements - Get all JSX elements in a class
- Function.jsx_elements - Get all JSX elements in a function
- JSXElement - Manipulate JSX elements
- JSXProp - Manipulate JSX props
See React Modernization for tutorials and applications of the concepts described here
Detecting React Components with is_jsx
Codegen exposes a is_jsx
property on both classes and functions, which can be used to check if a symbol is a React component.
Working with JSX Elements
Given a React component, you can access its JSX elements using the jsx_elements property.
You can manipulate these elements by using the JSXElement and JSXProp APIs.
Common React Operations
See React Modernization for more
Refactoring Components into Separate Files
Split React components into individual files:
See Moving Symbols for more details on moving symbols between files.
Updating Component Names and Props
Replace components throughout the codebase with prop updates:
Was this page helpful?