1

There are two user input text fields, and i want to show that data in a table using redux.

<tbody>
    <tr key={key}>
     <td>
       <TextField
         id="FirstName"
         label="First Name"
         type="name"
         value={this.state.fname}                                           
        />
      </td>
      <td>
       <TextField
         id="LastName"
         label="Last Name"
         type="name"
         value={this.state.lastname}                                            
        />
     </td>
   </tr>

Add icon

4
  • 1
    Have you tried integrating redux in your application? Have you tried to show user input values in table? Please try yourself and let us know what is not working. So that We can help Commented Nov 18, 2018 at 10:04
  • yes but how to save values from input to redux? Commented Nov 19, 2018 at 15:49
  • Why do you need to save input values to redux? Commented Nov 19, 2018 at 17:43
  • why dont you share your entire code which includes redux part as well. Commented Nov 21, 2018 at 4:12

1 Answer 1

1
Here is the solution,
Firstly To render it on a browser set the default values to your state variables.
constructor(props){
super(props);
this.state = {
fname : 'Foo ',
lastname : 'Bar',
}

}

Now, your code will get the value from state and it will render in DOM as you wanted. And use **defaultValue** in place of Value in input. Attribute 'value' is used when you are setting the values onChange but as you have already declared above in state , use **defaultValue** .

Like I have done below :-

<TextField
 id="FirstName"
 label="First Name"
 type="name"
 defaultValue={this.state.fname}                                           
  />
Sign up to request clarification or add additional context in comments.

4 Comments

This is not solution for OP’s problem. Moreover OP text inputs doesn’t even have event handler functions so how come anything can work just assigning state to value or defaultValue?
Though, I'm not using redux in dis , because for such a small functionality we don't require Redux , neither there are any API calls and if we talk about event handlers , the person has not used event handlers to set the values again and again , the values are directly called from { this.state} . Like from above , it will render in table the static values I have given , Foo and Bar.
i wanted to understand the flow so i will proceed in that way to use redx
For that , you need to write action, reducer for that. Please show all your files here so that we could help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.