我实施的旅游网站可供不同酒店使用。所以应用程序的一些主要颜色会有所不同。为了不为每个酒店使用不同的css类并将其应用于所需的组件(这将是最糟糕的解决方案),颜色将通过服务器发送。我的主要javascript文件是:
// Persist the store and start the application.
persistStore(store,
// Use session storage
{ storage: asyncSessionStorage },
() => {
sagaMiddleware.run(rootSaga);
render(
<Provider store={store}>
{routing(store)}
</Provider>
document.getElementById('main'));
}
);
我正在阅读有关上下文api的信息,但我的应用程序是使用react-redux redux-saga作为中间件等构建的。我们可以使用react-reactx的上下文吗?我的解决方案是将颜色存储在我的状态中,并将它们与每个组件中的style属性一起使用,如下所示:
<button
type="submit"
style={{backgroundColor: props.color}}
className={props.addedActivity ? 'add added' : 'add'}
>
<FormattedMessage
id={props.addedActivity ? 'added.activity.button' : 'add.activity.button'}
defaultMessage="_add.activity.button_"
/>
<img src={SeeMore} alt="see more button"/>
</button>