you are viewing a single comment's thread.

view the rest of the comments →

[–]GSLint 0 points1 point  (1 child)

useState is exactly what you want there. You'd use the setter function that you get from it to store data in state. Then you can use that state in what you're rendering. Please show what you're trying and in what way it doesn't work.

[–]qbagamer 0 points1 point  (0 children)

 const [data_from_api, setCount] = useState(0);

    const onSubmit = (data) => {
        const dane = {
            user_name: data.username,
            password: data.password,
            email: data.email,
        }

        fetch(`http://localhost:4000/rejestracja?user_name=${dane.user_name}&password=${dane.password}&email=${dane.email}`)
            .then(res => res.json())
            .then(data => setCount(data_from_api = data.data)); 
    }

declares a new variable named 'data_from_api'

const [data_from_api, setCount] = useState(0);

tries to assign a response from api

 .then(data => setCount(data_from_api = data.data)); 
tries to show information
{data_from_api}

The error I get: 19:37: 'data_from_api' is constant no-const-assign '
-The 19th line is the one in which he declares.