Hacker News new | ask | show | jobs
by vitriolum 1915 days ago
That's very interesting. I have pretty much all my components in React. How can you use React / jsx with constexpr?
1 comments

For react, you can use the `useEffect` hook to trigger compilation after the component renders:

    useEffect(() =>
      window._ConstexprJS_.compile()
    , [])
There's a babel jsx loader, that could be used. However, it dynamically compiles jsx to js and adds a script tag containing raw javascript to the DOM. You'll have to manually mark these new tags as 'constexpr', which shouldn't be too difficult.

Or you could compile jsx with webpack and then use it. With constexpr.js, the final static page will look exactly like the original dynamic page, so using the webpack output should be easy. I might add an example in the next week.

Thanks! I guess an example would be really cool, give the amount of FE devs who already use React.