admin管理员组文章数量:1333621
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
1 Answer
Reset to default 8In 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.
本文标签: javascriptHow to set Radio button selection programatically in react materialuiStack Overflow
版权声明:本文标题:javascript - How to set Radio button selection programatically in react material-ui - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742349649a2458231.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论