I am trying to find out the reaction, and I have some uncertainties. I referred to the DOCS reaction and some other lessons, and I saw that the functions are written inside the render function, as well as inside the class. What should we do inside the render function in the reaction?
First way
class App extends Component { test(user) { return user.firstName; } render() { const user = { firstName: 'Harper', lastName: 'Perez' }; return ( <div> <h1>{this.test(user)}</h1> </div> ) } }
Second way
class App extends Component { render() { const user = { firstName: 'Harper', lastName: 'Perez' }; function test(user) { return user.firstName; } return ( <div> <h1>{test(user)}</h1> </div> ) } }
Both of these methods work. But I want to know what is the best method for this? Most importantly, I want to know what I can do inside the render function.
Thanks.
source share