dom*_*mer 8 themes reactjs redux material-ui
我有以下使用自定义材质UI主题的React组件
const getTheme = name => themes.filter(theme => theme.name === name)[0] || 主题[0];
const Root = props => (
<MuiThemeProvider muiTheme={getMuiTheme(getTheme(props.theme).data)}>
<Router history={history}>
<Switch>
<Route component={AppContainer}/>
</Switch>
</Router>
</MuiThemeProvider>
);
Run Code Online (Sandbox Code Playgroud)
它由一个容器喂养
const mapStateToProps = state => ({
theme: state.settings.theme
});
const RootContainer = connect(mapStateToProps, {})(Root);
Run Code Online (Sandbox Code Playgroud)
当我在设置页面上更新主题名称时,状态会更新(通过Redux日志记录确认),但主题不会更新.但是,当我离开页面时,将应用新主题.
据推测,状态的改变不会导致Root组件重新渲染,或者在应用此方法时我不明白
<MuiThemeProvider muiTheme={getMuiTheme(getTheme(props.theme).data)}>
Run Code Online (Sandbox Code Playgroud)
知道如何让主题更新它在状态中更改的实例吗?
结果我还必须将更新的主题作为道具传递给我的应用程序组件(位于层次结构中的根下方)。似乎这与主题是通过上下文传递的事实有关,并且更改配置主题的组件中的道具不足以触发所需的更新。
| 归档时间: |
|
| 查看次数: |
2013 次 |
| 最近记录: |