I’m trying to setup a form. It has Edit feature where on edit I call an API and get the data into state.
I’m struggling to display data in the form after api call. There’s no problem utilizing the API or calling the redux functions. Problem is that my Form only displays last data in the redux state but not the updated data.
That’s how I’m doing the stuff.
-
Calling API if
isEdit===True
at the same time Form is being displayed on component mount. -
Updateding state after success as an object called
customer
-
accessing the customer object like this
const { customer } = useSelector((state) => state.customers)
Lets say I have a input field where I want to display the email of customer.
I’m handling this think like that:
email: isEdit ? customer?.email : '', // At this point there is some problem
It loads the previous data that was stored in the state.customer
but not the new one.
I believe my email field is rendering first and then doesn’t updated the value when change happens in state.customer
.
So how I can fix this? So that email value should be changed at the same time if state.customer got changed