简体   繁体   English

从javascript调用react组件

[英]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? 所以我有一个很大的项目,并且所有内容都在纯JavaScript上,例如Class.create ... prototype和函数,它们渲染该页面上的每个组件并使用react进行渲染。我的意思是当我以某种方式键入function.createElement(“ div”)时创建react div ..等等,所有内容都在PURE javascript ..上,所以我的问题是如何创建具有常规react组件的文件并从该js文件中调用该react组件? Thank you 谢谢

From what I understand from your question is that you need to reuse the react component. 据我所知,您需要重用react组件。 For that you need to do two things 为此,您需要做两件事

  1. Export you react component.You can do it as 导出您的react组件,您可以将其作为

     module.exports = App; 

    if your react component is like var App = React.createClass() 如果您的react组件就像var App = React.createClass()

  2. Secondly in your other react component where you want to reuse this component you can import it as 其次,在要重用此组件的其他react组件中,可以将其导入为

     import {App} from './path/to/resuable/component'; 
  3. Now use this component in the render() {} function as <App/> 现在,在render() {}函数中将此组件用作<App/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM