I am using a stateless component and got value from the json file, When I fetch data using map from json file object, then it will store only last data in state not whole objects:
import React, { useState, useEffect} from 'react'
import usersInformation from '../assets/dataconfig/users.json'
const Login = () => {
const [userEmail, updateEmail] = useState([]);
const [userPassword, updatePassword] = useState([]);
useEffect(function () {
const getUserdata = () => {
usersInformation.authorizedwebusers.map(item => {
console.log(item);
updateEmail([...userEmail, item.emailAddress]); // here store only last json data - [email protected]
updatePassword([...userPassword, item.emailpassword])
})
}
getUserdata();
}, [])
}
My json save as users.json:
{
"authorizedwebusers": [
{
"name": "Anil",
"emailAddress": "[email protected]",
"emailpassword": "123"
},
{
"name": "Lalit",
"emailAddress": "[email protected]",
"emailpassword": "123"
},
{
"name": "Shiv",
"emailAddress": "[email protected]",
"emailpassword": "123"
}
]
}