相关疑难解决方法(0)

React:从另一个组件调用 setState

这是父组件:

class Parent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      news: ""
    }
  }
  componentDidMount() {
    this.updateNews();
  }

  updateNews = () => {
      ...
  }

  render() {
      <CustomButton type="primary"  />
  }
Run Code Online (Sandbox Code Playgroud)

这是CustomButton

const CustomButton = (props) => {
  const {
    type
  } = props;


  const updateItem = () => {
     ... // The firing of the setState should be here
  }

  return (
   <Button
    type={type}
    onClick={() => {
        updateItem();
      }}
    >{value}
   </Button>
  );
Run Code Online (Sandbox Code Playgroud)

我怎样才能从内向const updateItem …

ecmascript-6 reactjs

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

ecmascript-6 ×1

reactjs ×1