score:0

Accepted answer

react renders when state and props of the component change. studentsarray is an array that is not a state nor a prop. so react doesn't know about the changes you have made. follow these steps to get reflection of the data

create state for student list

you need to store student list in state of the component

const [list, setlist] = usestate([])

set state in fetching logic

 useeffect(() => {
        const studentsarray = []; 
        axios.get("http://localhost:1337/api/getstudentsfromclass", {
            params: {currentclassclicked}
        }).then((response) => {
            setstudents(response.data.message)
            // console.log(response.data.message)
            for (let i = 0; i<response.data.message.length; i++){
                studentsarray.push(string(response.data.message[i].firstname))
            }
            setlist(studentsarray)
        })
    }, [])

use list in chart

use state list in dom

 return (
        <div classname='class-grades-container'>
            <h1>{currentclassclicked}</h1>
                <bar 
                    data={{
                        labels: list,
                        datasets: [
                            {
                                label: "student grades",
                                data: [30, 80, 20, 10]
                            }
                        ]
                    }}
                />
        </div>
    )

Related Query

More Query from same tag