Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在不使用mobx渲染的情况下对道具更改作出反应_Reactjs_Mobx_Mobx React - Fatal编程技术网

Reactjs 如何在不使用mobx渲染的情况下对道具更改作出反应

Reactjs 如何在不使用mobx渲染的情况下对道具更改作出反应,reactjs,mobx,mobx-react,Reactjs,Mobx,Mobx React,我正在构建一个React+Mobx应用程序,我有一个组件不呈现任何内容,因为它都基于第三方地图API,但我需要对一些商店属性更改做出反应: componentDidMount(){ mapApi.doSomething(this.props.store.value) } 组件将反应(){ mapApi.doSomething(this.props.store.value) } 渲染(){ //使componentWillReact触发器 console.log(this.props.store.

我正在构建一个React+Mobx应用程序,我有一个组件不呈现任何内容,因为它都基于第三方地图API,但我需要对一些商店属性更改做出反应:

componentDidMount(){
mapApi.doSomething(this.props.store.value)
}
组件将反应(){
mapApi.doSomething(this.props.store.value)
}
渲染(){
//使componentWillReact触发器
console.log(this.props.store.value)
返回空
}
有没有一种优雅的方法来实现这一点?

您可以使用


如果我理解正确,您希望对渲染函数中未使用的内容做出反应。您可以这样做:

@observer 
class ListView extends React.Component {
   constructor(props) {
      super(props)
   }

@observable filterType = 'all'

handleFilterTypeChange(filterType) {
  fetch('http://endpoint/according/to/filtertype')
    .then()
    .then()
}

  // I want the method that autoruns whenever the @observable filterType value changes
 hookThatDetectsWhenObservableValueChanges = reaction(
    () => this.filterType,
    filterType => {
      this.handleFilterTypeChange(filterType);
    }
 )
} 
这里提到了这个解决方案

@observer 
class ListView extends React.Component {
   constructor(props) {
      super(props)
   }

@observable filterType = 'all'

handleFilterTypeChange(filterType) {
  fetch('http://endpoint/according/to/filtertype')
    .then()
    .then()
}

  // I want the method that autoruns whenever the @observable filterType value changes
 hookThatDetectsWhenObservableValueChanges = reaction(
    () => this.filterType,
    filterType => {
      this.handleFilterTypeChange(filterType);
    }
 )
}