我是一个初学者,难以理解 React 钩子。
我有使用钩子的子组件“RadioButtonsGroup”(由 MUI 构建):
function RadioButtonsGroup() {
const [value, setValue] = React.useState('isAgent');
function handleChange(event) {
setValue(event.target.value);
}
return (
<FormControl component="fieldset">
<RadioGroup aria-label="Gender" name="gender1" value={value} onChange={handleChange}>
<FormControlLabel
value="isAgent"
control={<Radio color="primary" />}
label="Agent"
labelPlacement="start"
/>
<FormControlLabel
value="isLandlord"
control={<Radio color="primary" />}
label="Landlord"
labelPlacement="start"
/>
</RadioGroup>
<FormHelperText>labelPlacement start</FormHelperText>
</FormControl>
);
}
Run Code Online (Sandbox Code Playgroud)
我如何将道具从它的父级传递给这个“RadioButtonsGroup.js”?我试着用
<RadioButtonsGroup isAgent={false} />
Run Code Online (Sandbox Code Playgroud)
但似乎没有 this.props.isAgent 传递给 child 并且根本没有 this.props 。
我可以在第一个控制台中看到我的响应,但始终是undefined。
fetch("/api/v1/legacy/tenant-shop", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(dataToSubmit)
})
.then(response =>
console.log("THIS RESPONSE IS WORKING, IT CONSOLE 201", response.status)
)
.then(response => {
if (response && response.status === 201) {
console.log("BUT IT NEVER GOES THERE");
this.props.router.push("/congratilations");
} else {
console.log("THE RESULT OF THIS CONSOLE IS NULL", response && response);
}
});
Run Code Online (Sandbox Code Playgroud)