Expression Before Return Of A Method In React
I have a method in my render method render(){ const { x } = this.state; return( {this.someMethod(x)} ) } someMethod(x){ return(
some conte
Solution 1:
Wrap your call within a div and assign the expression value to another variable
classAppextendsReact.Component {
state = { x: 1}
someMethod(x){
console.log('here');
var g = (x === 1) ? 2: 3return(
<div>some content {g}</div>
)
}
render(){
const { x } = this.state;
return(
<div>{this.someMethod(x)}</div>
)
}
}
ReactDOM.render(<App/>, document.getElementById('app'))
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script><divid="app"></div>
Post a Comment for "Expression Before Return Of A Method In React"