Я хочу получить атрибут RadioButton при первом запуске страницы (например, при первом вызове componentWillMount ())
Я буду сравнивать эту проблему с JQuery.
$(function() {
var radioAttr = $('#radioButton_id').find("option:selected").val()
});
Я хочу реализовать исходный код JQuery для React Hooks. если вы знаете, как, пожалуйста, помогите мне ..
const UserEdit = ({ classes, ...props }) => {
const types = [
{id:'INDIVIDUAL'},
{id:'COMPANY'}
];
const [ checked, setChecked ] = useState(true);
const onClickRadioBtn = (event,id) => {
(id === "COMPANY") ? setChecked(false) : setChecked(true)
};
useEffect(()=>{
**/* get radioButton attr */**
});
return(
<Edit {...props}>
<SimpleForm>
<TextInput source="username" validate={required()}/>
<TextInput source="email" validate={[required(),email()]}/>
<TextInput source="phoneNumber" validate={[required(),minLength(10),number()]}/>
<RadioButtonGroupInput label="Type"
source="userType"
choices={types}
optionText="id"
validate={required()}
onChange={onClickRadioBtn}
/>
{ !checked && (
<ReferenceInput label="Company" source="company.id" reference="companies" validate={required()}>
<SelectInput optionText="name"/>
</ReferenceInput>
)}
</SimpleForm>
</Edit>
);
};