小编pol*_*ova的帖子

将道具从父组件传递给使用钩子的子组件?

我是一个初学者,难以理解 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 。

reactjs react-hooks

3
推荐指数
1
解决办法
3297
查看次数

React Fetch返回未定义,但在控制台中它返回响应

我可以在第一个控制台中看到我的响应,但始终是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)

post fetch reactjs

0
推荐指数
1
解决办法
330
查看次数

标签 统计

reactjs ×2

fetch ×1

post ×1

react-hooks ×1