最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to set Radio button selection programatically in react material-ui - Stack Overflow

programmeradmin0浏览0评论

I am using radio button group from material-ui. I can set defaultSelected to have a default selection but once rendered, i won't be able to set it programatically. It only changes when you click the radio. Is this something which we can do with material-ui?

I am using radio button group from material-ui. I can set defaultSelected to have a default selection but once rendered, i won't be able to set it programatically. It only changes when you click the radio. Is this something which we can do with material-ui?

Share Improve this question asked Aug 27, 2016 at 8:15 mtsandeepmtsandeep 3301 gold badge3 silver badges11 bronze badges 1
  • can you share your code so that we can check – Md.Estiak Ahmmed Commented Aug 27, 2016 at 10:08
Add a ment  | 

1 Answer 1

Reset to default 8

In react ponents can be either controlled or uncontrolled. Controlled means that you set that ponent value yourself and you keep the value in the parent ponent as well in a state or prop. While uncontrolled ponent means that you only set a default value and you let the ponent handle the rest.

Now in most cases you would need a ponent that edits a value to send that value out to its parent, for sending a server request or just storing this value in the application state, so I would argue that in most cases you should use a controlled ponent.

To do this in material-ui instead of setting the 'defaultSelected' propery use the 'valueSelected' property and set it to a prop or state variable, also use the 'onChange' callback to set the state value or propagate the callback outside where you will eventually change the state in a controller ponent or update the application state in some store.

发布评论

评论列表(0)

  1. 暂无评论