In react I need to set a prop based on the return value from a function. I want to try to avoid using state for this and I am getting a variable from localstorage so that the user can pick up where they left off. This is the function that returns the value from local storage:
const getCustomerId = () => {
return getItem('customerId').toString();
};
Then I have a provider that needs access to the customerId from localstorage. I try to pass the functions return value as a prop but the prop is supposed to be a string and its giving it a function still :
<ProfileProvider
id="1"
email={user?.email}
setSelectedCustomer={handleChangeCustomer}
customerId={getCustomerId}
>
Also when the handleChangeCustomer is called, the getCustomerId should be called from within it to change. so should the prop of customerId with the updated value from localStorage.
Im not sure how this can done without using state.
handle customer function:
const handleChangeCustomer = id => {
setLocalCustomer(id);
getCustomerId();
};