class PrintProbability extends React.Component { render(){ return( {(()=>{ if(!isNaN(this.props.probability)){ <div>{this.props.roletype}確率 :<br/> 1/{(this.props.probability).toFixed(1)}<hr/></div> }else{ <div>未入力です。</div> } })()} ) } }
Reactで確率を計算して表示するコンポーネントで、親コンポーネントから受け取った
this.props.probabilityがNaNの時とそうでない時で表示を切り替えたいです。
即時関数を使った上のコードで動かすと
babel.js:14449 Uncaught SyntaxError: Inline Babel script: Unexpected token (369:5) 367 | render(){ 368 | return( > 369 | {(()=>{ | ^ 370 | if(!isNaN(this.props.probability)){ 371 | <div>{this.props.roletype}確率 :<br/> 1/{(this.props.probability).toFixed(1)}<hr/></div> 372 | }else{ at Parser.pp$5.raise (babel.js:14449) at Parser.pp.unexpected (babel.js:11756) at Parser.pp$3.parseIdentifier (babel.js:14327)
上記のようなエラーが出ます。何が原因なのでしょうか。書き方のような気がするのですが。
条件分岐なしのコンポーネントの場合エラー無しで動くので、ここが原因だと思います。

回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/04 12:40
2019/08/04 13:05
2019/08/06 00:42
2019/08/06 00:47
2019/08/06 06:02
2019/08/06 06:22
2019/08/07 08:57