[英]How to get firstname and lastname from email provider in node.js?
[英]how to display element firstname and lastname ... from strore redux
在這里找到我的代碼,當我嘗試獲取名字時,我得到了“無法讀取未定義的屬性”的問題,有人可以提供解決方案或解釋我的代碼有什么問題嗎
let state = useSelector(state => {
// console.log('State: ', state.profile);
return state.profile;
});
const [profile, setProfile] = useState();
const [formState, setFormState] = useState({
isValid: false,
values: {},
touched: {},
errors: {}
});
useEffect(()=>{
console.log({accesstoken: token});
if(token)
dispatch(profileActions.getInfos({accesstoken: token}));
},[])
useEffect(()=>{
if (state)
setProfile(state)
console.log(profile.profile);
},[state, profile])
/// here the peace of code to display the profile.data.firstname
ListItemText primary="Date de creation" secondary{JSON.stringify(profile.data.firstName)} />
您是否在 useEffect 之前對變量 state 進行了控制台操作。 我想不需要使用(useState & useEffect)你可以直接使用你的變量 state。 嘗試在 useEffect 之前或之后添加 console.log(state) 並與 as 共享。
我試試
const profile = useSelector(state => state.profile.profile.data);
console.log(profile);
output => {
"_id": "61d6cbe4e3afe444b1500f50",
"email": "fridmahdi@live.fr",
"firstName": "elmahdi",
"lastName": "frid",
"number": null,
"created_at": "2022-01-06T11:00:52.009Z",
"is_verified": null}
const profile = useSelector(state =>state.profile.profile.data.firstName)
但是當我像這樣添加我需要的字段時,我變得不明確
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.