27 ms·
Related to this, how would someone who has existing websites built with various other libraries start a migration to React? I have a lot of legacy YUI code in
by rdoherty 11y ago
Related to this, how would someone who has existing websites built with various other libraries start a migration to React?
I have a lot of legacy YUI code in a Rails app (using Rails' asset pipeline) that I want to rewrite. Anyone have resources on how to get setup and refactor in pieces?
- firasd 11y agoYou can just start writing JS on an existing page to output components rendered by React. Fair warning though, React is focused on rendering and initializing, so it doesn't come with a bunch of handy JS functions like YUI or jQuery. But you can use React & other JS libs together, as long as you're careful that the other JS lib doesn't change the markup of a React component (which would take it out of sync.)
- mercurial 11y agoI'm doing exactly that at work. When you write React code (whether for a single-page React application or a mostly-legacy application), there is a point where you need to tell React to start rendering a root component inside a given, existing DOM element. Your legacy application should NOT mess with anything under this DOM element, as this will be solely managed by React. However, it is entirely possible to have several of these root components on the same HTML page. It makes it possible to refactor a complex page progressively. You're still going to run into issues if you need communication between legacy and Reactified UI elements, though. You will need to setup, eg, listeners manually. In the case where you need to update parts of a form, just tell your React store to write to hidden input fields instead of doing Ajax with the server.
- 1stop 11y agoOne approach would be to rewrite each page completely in react. Using the Rails app as an API.