有两个用户输入文本字段,我想使用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>
添加图标
答案 0 :(得分: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** .
就像我在下面一样:-
<TextField
id="FirstName"
label="First Name"
type="name"
defaultValue={this.state.fname}
/>