mercredi 20 novembre 2019

How to get the return expression of a React component?

Is there a way to get the return expression of a React component.

I tried different methods such as trying to parse the function prototype but nothing worked so far. The only way that looks feasible is to parse the file as a string but that seems very complex to implement.

Simple.js

const React = require("React");

const Simple = (props) => (
    <div><span>text {2+2}</span></div>
)
module.exports = Simple;

Index.js

const Simple = require("./Simple");

Simple.getRenderExpression() // <div><span>text {2+2}</span></div>

Note: I'm looking to get the "render expression" not the "render string" that can be access with ReactDOMServer.renderToString(element). That in my case would have been "text 4".





Aucun commentaire:

Enregistrer un commentaire