如何在 ReasonML 中将 Variants 作为 props 传递给 React Components?
How do I pass Variants as props to React Components in ReasonML?
我尝试了以下方法来将变体作为道具发送。
type ipAddr =
| IPV4
| IPV8;
[@react.component]
let make = () => {
let appData = Data.tileData;
<div className="App">
<header className="flex outline justify-between" />
<Content selected={ipAddr.IPV4} appData />
</div>;
};
但是它抛出错误,
ninja: error: rebuilding 'build.ninja': subcommand failed
我也试过将变体直接发送到组件。
<div className="App">
<header className="flex outline justify-between" />
<Content selected=IPV4 appData />
</div>;
但它最终返回了另一个错误
Start compiling ninja: error: dependency cycle: src/App-ReactHooksTemplate.cmj -> src/Content-ReactHooksTemplate.cmj
-> src/App-ReactHooksTemplate.cmj
Finish compiling(exit: 1)
我哪里错了?
免责声明:我不知道 ReasonML,但是
如果是OCaml,你只需要写IPV4
,不需要像ipAddr.IPV4
那样限定它。
也许这在 Reason 中也是一样的?
我用另一种方法解决了这个问题。我没有将变体作为 prop 传递,而是根据变体值简单地渲染了不同的组件。
[@react.component]
let make = () => {
let appData = Data.tileData;
switch (selected) {
| IPV4 =>
<div>
<IPV4Renderer appData />
</div>
| IPV6 =>
<div>
<IPV6Renderer appData />
</div>
};
};
我尝试了以下方法来将变体作为道具发送。
type ipAddr =
| IPV4
| IPV8;
[@react.component]
let make = () => {
let appData = Data.tileData;
<div className="App">
<header className="flex outline justify-between" />
<Content selected={ipAddr.IPV4} appData />
</div>;
};
但是它抛出错误,
ninja: error: rebuilding 'build.ninja': subcommand failed
我也试过将变体直接发送到组件。
<div className="App">
<header className="flex outline justify-between" />
<Content selected=IPV4 appData />
</div>;
但它最终返回了另一个错误
Start compiling ninja: error: dependency cycle: src/App-ReactHooksTemplate.cmj -> src/Content-ReactHooksTemplate.cmj -> src/App-ReactHooksTemplate.cmj Finish compiling(exit: 1)
我哪里错了?
免责声明:我不知道 ReasonML,但是
如果是OCaml,你只需要写IPV4
,不需要像ipAddr.IPV4
那样限定它。
也许这在 Reason 中也是一样的?
我用另一种方法解决了这个问题。我没有将变体作为 prop 传递,而是根据变体值简单地渲染了不同的组件。
[@react.component]
let make = () => {
let appData = Data.tileData;
switch (selected) {
| IPV4 =>
<div>
<IPV4Renderer appData />
</div>
| IPV6 =>
<div>
<IPV6Renderer appData />
</div>
};
};