Radio Button Group defaultChecked prop Not Working #3784
-
Hey, Can you help me out ?? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
🤖 Hey there, @ehsaan-changa! 👋 Good to see you back. I remember working through some stuff with you before. Let me dive into this RadioButtonGroup issue and I'll circle back with what I find. Stay tuned! 🕵️♂️ |
Beta Was this translation helpful? Give feedback.
-
Disclaimer: This is a very experimental bot using OpenAI's GPT-4. The answers may not be correct, a human will review the answer and update it if necessary. Sorry, I don't know how to help with that. I did do a search though, and I managed to find these other Discussions that might be similar or related to your question. Give them a read to see if they answer your question. If they do, head back here and update this discussion and mark it as answered, pointing others to the related discussion:
|
Beta Was this translation helpful? Give feedback.
-
🤖 Based on your description, it seems like you're encountering an issue with the In the The component then determines if it is controlled or uncontrolled. It is considered controlled if the If the component is uncontrolled, it uses the Here is the relevant code: const isControlled = React.useMemo(() => checked !== undefined || radioGroupContext.value !== "", []);
// ...
if (isControlled) {
// Use context's value first
if (radioGroupContext.value !== "") {
state.checked = radioGroupContext.value === value;
} else {
// Then checked prop on this radio
state.checked = checked;
}
} else {
// Lastly fall back to default checked if state isn't controlled
state.defaultChecked = defaultChecked;
} You can find this code in the RadioButton.tsx file. So, if you're providing a If you're still encountering issues, could you provide a code snippet of how you're using the Sources
|
Beta Was this translation helpful? Give feedback.
-
Hi there If you could provide a simple reproduction of your issue in a codesandbox that would be helpful. Initial thoughts though, are that Dosu is hinting you in the right direction, with controlled and uncontrolled input components in React. Just like Radio group, or any radio button control when using React, you can't mix controlled and uncontrolled when using a component. Furthermore, you can't use From that code snippet, that's what you seem to be doing, controlling state but trying to render the radio's checked status as if it was an uncontrolled component. |
Beta Was this translation helpful? Give feedback.
Hi there
If you could provide a simple reproduction of your issue in a codesandbox that would be helpful.
Initial thoughts though, are that Dosu is hinting you in the right direction, with controlled and uncontrolled input components in React.
Just like Radio group, or any radio button control when using React, you can't mix controlled and uncontrolled when using a component. Furthermore, you can't use
defaultChecked
on checkboxes or radios when the component is controlled by your state. Your state must control the checked state of the component.From that code snippet, that's what you seem to be doing, controlling state but trying to render the radio's checked status as if it was an unco…