import MyComponent from './MyComponent'
const { component, setComponent } = useState();
setComponent(MyComponent) // < how to pass props here?
稍后在做类似的事情
const Component = () => component;
<Component />
在这种情况下,我在这里没有多大意义,但只是想说明我需要如何传递道具
也许这会有所帮助:
import MyComponent from './MyComponent'
const [component, setComponent] = useState(null);
setComponent(<MyComponent prop1="property"/>)
只需将一个函数传递给状态,即可返回组件。
这有效
setComponent(MyComponent({prop1: 'value}))
import MyComponent from './MyComponent'
const { component, setComponent } = useState();
setComponent(<MyComponent prop={$prop} {...props}/>)