我可以传递具有额外结构化价值的道具吗?

can I pass props with additional distructured value?

我正在尝试从 redux 获取传递值,我可以将值作为 props 和另一个解构值传递吗?

我的代码是这样的:

function MyFunction(props, {cityData}) {
  console.log(props);

  useEffect(() => {
    props.fetchCity();
  }, []);

  return props.cityData.loading ? (
    <Typography>Loading</Typography>
  ) : props.cityData.error ? (
    <Typography>{props.cityData.message}</Typography>
  ) : (
    <div></div>
  );
}

是的,你可以。您可以根据您的代码解构您的道具,如下例所示

function MyFunction(props) {
  console.log(props);
  const {cityData} = props;

  useEffect(() => {
    props.fetchCity();
  }, []);

  return cityData.loading ? (
    <Typography>Loading</Typography>
  ) : cityData.error ? (
    <Typography>{cityData.message}</Typography>
  ) : (
    <div></div>
  );
}