Movatterモバイル変換


[0]ホーム

URL:


ReasonReact

ReasonReact

Edit

I want to create a DOM element without JSX

In certain cases, you might want to choose the DOM element given props, and JSX prevents that.

In JS, you'd do:

React.createElement(multiline ?"textarea" :"input"/* ... */);

ReactJS has a special behavior that considers strings as special components. In a typed language, that's a bit trickier. To that end we provideReactDOM.stringToComponent that makes the compiler understand that a given string is to be considered a component.

In Reason:

React.createElement(ReactDOM.stringToComponent(multiline ?"textarea" :"input"),/* ... */)

You can also pass a variable:

let tag =ReactDOM.stringToComponent(multiline ?"textarea" :"input");React.createElement(tag,/* ... */)
I Really Need Feature X From ReactJS

[8]ページ先頭

©2009-2025 Movatter.jp