0

I have a select option and I want to link the user to another comp when clicked everything going well,the user is redirected and see the comp. But, the option doesn't change in the select label, and still shows the first option all the time. see code below:

`

    <Select portfolio dir="rtl" 
            onChange={(e)=>{
              history.push(`${e.target.value}`); 
              }}>
     <Option value='/account/details'>details</Option>
      <Option value='/account/projects' >projects</Option>
      <Option value='/account/changepassword'>pass</Option>
      {user&& (
      <Option value='/account/requests'>messages</Option>
      )}
      </Select>
      );
    };

`

edit i use the regular select input . and still dont understand the problem. in other component i have this select option (without link) and its work and change the "title text" op the option when i change.

its looking the same and its work:

    <Select small dir="rtl" 
        onChange={(e)=>{
          return catFilter(e.target.value)
          }}>

  <Option key='' value=''>all</Option>;
{categories&&categories.map((opt, key) => {
        return <Option key={key} value={opt.id}>{opt.fullName}</Option>;

      })}

      </Select>

i dont see the difference...

  • you need to pass the current value to the Select component. depending on the components props expectations it will probably be the "value" prop – Tom Slutsky Apr 20 '20 at 06:20
  • :/.. still dont understand. note that i have another select option exactly the same but without the link o react-router and its work perfectly. so i think its some issue with the react-router – Roei Grinshpan Apr 20 '20 at 09:15
  • The select component is the one "knowing" which of the options is selected. however at the moment it doesn't. you need to provide the `value` prop to Select. which component library do you use? – Tom Slutsky Apr 20 '20 at 09:51
  • i still dont understand why change the state, i have same select option in another comp (without Link) and its worked perfectly. (i edited the post so see code there..) – Roei Grinshpan Apr 20 '20 at 11:24
  • 1
    i think that the problem is that i have
    inside the options and its render all or somehing, anyway problem solved thank u
    – Roei Grinshpan Apr 22 '20 at 08:22

0 Answers0