If React offers DOM reconciliation, is it possible to dynamically reload component's code and re-render it after I edit it?
I'm looking for a solution that allows me to edit JSX file, save it, and have the component update itself in the browser, without reloading the page, unmounting it or losing its state.
Ideally this should work without browser plugins.
When you're inside a react component, the props has history , you can use that. Then you can import browserRouterRef anywhere and use browserRouterRef. current. history to change the route even if you are not inside a react component.
reload(false); This method takes an optional parameter which by default is set to false. If set to true, the browser will do a complete page refresh from the server and not from the cached version of the page.
You can do something like this. In the Quote. js create getNewQuote function and call that function inside the useEffect . Then, pass the getNewQuote function to the Button component and on New Quote button onClick set getNewQuote .
You can use react-hot-loader, a drop-in Webpack loader that enables live editing for React components in your projects. No browser plugins or IDE hooks required.
It marries Webpack Hot Module Replacement (HMR) with React.
You can use this if:
How it works:
React.createClass
calls to special createClass
and updateClass
functions that store the component's prototype and later update it with fresh version;forceUpdate
to re-render the components.There is a demo video, an explanatory blog post and a React tutorial app fork with live-edit configured.
And it's all vanilla JS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With