import React from 'react'
import { Input, Form, Button } from 'antd';
import { LockTwoTone, MailTwoTone, EyeTwoTone, EyeInvisibleOutlined } from '@ant-design/icons';
import { login } from '@/services/Api.Login/index'
import { getProfile } from '@/services/Api.User';
const LoginForm = () => {
const onFinish = async (values) => {
const { email, role, userName, organisationId } = await getProfile(values);
localStorage.setItem('email', email);
localStorage.setItem('role', role);
localStorage.setItem('userName', userName);
localStorage.setItem('organisationId', organisationId);
// var items = [ 'email', 'role', 'userName', 'organisationId' ]
};
return (null)
}
export default LoginForm
Asked
Active
Viewed 52 times
-1

wangdev87
- 8,611
- 3
- 8
- 31
-
2Can you go into more detail? – Daniel_Knights Dec 10 '20 at 08:08
-
Possible duplicate of [this](https://stackoverflow.com/questions/8419354/get-html5-localstorage-keys) – ISD Dec 10 '20 at 08:08
-
store it in an array and loop through the array. – Aalexander Dec 10 '20 at 08:09
2 Answers
1
const onFinish = async (values) => {
const result = await getProfile(values);
const items = [ 'email', 'role', 'userName', 'organisationId' ]
items.forEach(key => {
localStorage.setItem(key, result[key]);
});
};

wangdev87
- 8,611
- 3
- 8
- 31
0
Instead of this
const { email, role, userName, organisationId } = await getProfile(values);
You can store it in an array
const arr = await getProfile(values);
Then use this what you have in the commentary as foundation for the loop
var items = [ 'email', 'role', 'userName', 'organisationId' ]
Loop through it
items.forEach(key => {
localStorage.setIteam(key, arr[key]);
});

Aalexander
- 4,987
- 3
- 11
- 34