FreakProgrammer FreakProgrammer - 1 month ago 18
React JSX Question

Call react component from javascript

so i have that big project and everything is on pure javascript like Class.create...prototype and functions that render every component on that page and in render with react.I mean when i type function.createElement("div") somehow it create react div.. and so on and everything is on PURE javascript .. so my question is how can i create file with normal react components and and call that react component from that js file? Thank you

Answer

From what I understand from your question is that you need to reuse the react component. For that you need to do two things

  1. Export you react component.You can do it as

    module.exports = App;
    

    if your react component is like var App = React.createClass()

  2. Secondly in your other react component where you want to reuse this component you can import it as

    import {App} from './path/to/resuable/component';
    
  3. Now use this component in the render() {} function as <App/>