22
rated 0 times
[
24]
[
2]
/ answers: 1 / hits: 9188
/ 4 Years ago, sat, may 16, 2020, 12:00:00
I use React js ,There is a variable in the App.js
file called Persons
.
I want the Persons
value to be updated every time I click on the button.
import React from react;
import ./styles.css;
import Button from @material-ui/core/Button;
import EleventHeaderCard from ./ElevatedHeaderCard;
import axios from axios;
export let persons = [
{
id: 9,
email: [email protected],
first_name: Michael,
last_name: Lawson,
avatar: https://s3.amazonaws.com/uifaces/faces/twitter/follettkyle/128.jpg
},
{
id: 10,
email: [email protected],
first_name: Lindsay,
last_name: Ferguson,
avatar: https://s3.amazonaws.com/uifaces/faces/twitter/araa3185/128.jpg
}
];
const handleClick = () => {
return axios.get(`https://reqres.in/api/users?page=2`).then(res => {
persons = res.data.data;
console.log(persons);
});
};
export default function App() {
return (
<div className=App>
<Button color=primary type=Submit onClick={handleClick}>
click me !!!
</Button>
<EleventHeaderCard />
</div>
);
}
Here you can see my codesandbox
More From » reactjs