Function inside render and class in reactjs : <p>I'm trying to learn reactjs and i have some uncertainties. I was refering react DOCS and some other tutorials and i saw functions are written inside render function and also inside class. What things should we do inside render function in react?</p>

<p>1st way</p>

<pre><code>class App extends Component {

    test(user) {

        return user.firstName;
    }

    render() {

        const user = {
            firstName: 'Harper',
            lastName: 'Perez'
        };

        return (

            &lt;div&gt;

                &lt;h1&gt;{this.test(user)}&lt;/h1&gt;

            &lt;/div&gt;
        )
    }
}
</code></pre>

<p>2nd way</p>

<pre><code>class App extends Component {

       render() {

        const user = {
            firstName: 'Harper',
            lastName: 'Perez'
        };

        function test(user) {

            return user.firstName;
        }

        return (

            &lt;div&gt;

                &lt;h1&gt;{test(user)}&lt;/h1&gt;

            &lt;/div&gt;

        )

    }
}
</code></pre>

<p>Both this methods work. But i want to know what is the best method to do this? Most importantly i want to know what kind of things i can do inside render function.</p>

<p>Thanks.</p>
