0

I have a Redux form on a page that is for user profile data. This page has locaton options for state and city as option boxes. When the user selects a value, I get the ID of the item in the array and then store that to the DB. When the user goes back to the profile page, how do I set the state and city that was previously saved do they would see the proper state and city on the page? For example, if New Your was saved as the state, that is what the user should see when entering the page.

I have tried setting the value, text, field...nothing seems to work.

return await restAPI.get('/api/customers/profiles/me', currentUser.id).then(userProfile => {

    this.setState ({
     firstName: userProfile.firstName,
     lastName: userProfile.lastName,
     companyPhone : userProfile.companyPhone,
     cellPhone : userProfile.cellPhone,
     email: userProfile.email,
     age: userProfile.age,
     asset: userProfile.asset,
     birthday: userProfile.birthday,
     city: userProfile.cityId,
     role: userProfile.role,
     state: userProfile.stateId
    })
});

<Field
component={this.selectComponent}
name="state"
id="state"
onChange={(e, newValue) =>this.handleStateChange(e, newValue)}
> 
{this.state.states.map((state, i) => (
  <option key={i} value={state}>
    {" "}
    {state}{" "}
  </option>
))}
</Field>
Baub
  • 723
  • 4
  • 21
  • 36
  • Have you tried setting the `selected` value in the ` – user Jul 06 '18 at 17:45
  • I just tried that as well as defaultValue, neither worked. I tried passing in a number and a string, both did not work: – Baub Jul 06 '18 at 17:52
  • I do not quite understand, **What do you mean here** _"When the user goes back to the profile page"_ ...Do the user was in another component? – Liam Jul 06 '18 at 18:33
  • Go into the Profile page and save some data. Save pushes user to the dashboard of the web app (a different page), if the user goes back to the Profile page, they should see all saved data. When the user enters the page I can get the saved data from the database but don't know how to set the value of the option box. – Baub Jul 07 '18 at 19:58

0 Answers0