Creating global components
Compared to basic common components, it is common component of global components on the general assembly to create DOM
can be.
// Test未普通组件
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
class Test extends Component{
show = ()=>{
//...
};
hidden = ()=>{
// ...
};
//...
}
let div = document.createElement('div');
document.body.appendChild(div);
let box = RaectDOM.render(React.creatElement(
Test
),div);
export default box;
Use global components
Only need to introduce global components in the component, and then call the global assembly method can be directly.
import React, {Component} from 'react';
import Test from './Test.jsx';
class Ceshi extends Component {
render(){
return (
<div>
<button onClick={Test.show}>测试</button>
</div>
);
}
}
export default Ceshi;