Developer Docs

React Functional Component

Functional components are the newest way of creating React components and managing state without using a class. They use the new hooks feature to manage state.

In the following example name is the state variable, setName is the function to call if you want to change state and useState("") is used to describe this variable as a state variable and initialise it to the empty string.

import React, { useState } from "react";

export default function PersonInfo() {
    const [name, setName] = useState("");
    return (
        <>
            <div>
                <p>Entered Name: {name}</p>
                <p>Name</p>
                <input
                    type="text"
                    onChange={(e) => {
                        setName(e.target.value);
                    }}
                />
            </div>
        </>
    );
}

To change state we call the setName method whenever there is a change. This is the same method we declared earlier in the function to control our state. For more information on managing lifecycle state of components please checkout the official documentation.

Was this article helpful?

Thanks for your feedback!

If you would like to tell us more, please click on the link below to send us a message with more details.

Tool:

Generate

Iterate

Bot:

C#Bot

SpringBot

On this page

New to Codebots?

We know our software can be complicated, so we are always happy to have a chat if you have any questions.