我希望每次调用&#39; state.set(...)&#39;,时我的组件都会重新渲染,即使值没有变化。 < / p>
所以嘿伙计们,我有这个减速机,每次调整屏幕都会调用它:
import Immutable from 'immutable';
const initialState = Immutable.fromJS({
width: ''
});
export default (state=initialState, action) => {
switch(action.type){
case "SCREEN_RESIZE":
if(action.payload >= 768){
return state.set('width', 'big');
}
else{
return state.set('width', 'small');
}
default:
break;
}
return state;
}
我使用ImmutableJS和redux,所以我的商店是地图(整个商店)的地图(每个减速器)。
问题是,当我们更改“宽度”时,我的组件才会重新渲染。来自&#39; big&#39;小&#39;小&#39;小&#39;小&#39;到了&#39; big&#39;,也就是说,当价值发生变化时!
我希望它重新渲染,即使我设置的宽度来自“大&#39;大&#39;到&#39;大&#39;或来自&#39; small&#39;小&#39;。
我犯了什么错误吗?
这是我的rootReducer
import { combineReducers } from 'redux-immutable';
import reducer1 from './reducer1_reducer';
import reducer2 from './reducer2_reducer';
import reducer3 from './reducer3_reducer';
import screenSize from './screenSize_reducer';
import reducer5 from './reducer5_reducer';
import rounting from './routerReducer';
const rootReducer = combineReducers({
reducer1,
reducer2,
reducer3,
screenSize,
reducer5,
routing
});
export default rootReducer;
答案 0 :(得分:0)
如果你想在每个屏幕上重新渲染大小,你可能会想要让组件的道具具有实际的屏幕尺寸,如下所示:
<MyRerenderableComp width={this.props.screenWidth} height={this.props.screenHeight} />
您的问题与此帖有些相似:Reactjs - Rerender on browser resize
希望有帮助吗?