[英]How to create object with a value from redux store
I want to create an object with specific getters and one key which is language. 我想创建一个具有特定吸气剂和一个语言键的对象。 Based on language key getters should return different values. 基于语言的键获取器应返回不同的值。 Its for custom language chooser option. 它用于自定义语言选择器选项。 For example, I have a getter 例如,我有一个吸气剂
get homePage() {
return lang === 'eng' ? "Home" : "Ui"
}
Object is 对象是
export const contents = { lang: 'eng', get homePage() { return lang === 'eng' ? "Home" : "Ui" } }
Action 行动
export const setLang = lang => ({
type: SET_LANG,
lang
});
lang is stored inside redux store, now I want to update object whenever it changes. lang存储在redux存储中,现在我想在对象更改时更新它。 Then use that objects inside other components. 然后在其他组件中使用该对象。 But I do not know how to access redux store inside object. 但是我不知道如何访问对象内部的redux存储。 Any suggestions? 有什么建议么?
I think you should use selectors for redux, for example: const getBelts = (state) => state.items.belts
我认为您应该为redux使用选择器,例如: const getBelts = (state) => state.items.belts
Although your case is a little bit odd but if you really need to do it this way then you can use the store
object that you return from createStore
function and then use a selector function to query the store. 尽管您的情况有些奇怪,但是如果您确实需要这种方式,则可以使用从createStore
函数返回的store
对象,然后使用选择器函数来查询商店。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.