Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.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 如何将组件(文件)连接到redux存储_Reactjs_React Native_Redux_React Router_React Redux - Fatal编程技术网

Reactjs 如何将组件(文件)连接到redux存储

Reactjs 如何将组件(文件)连接到redux存储,reactjs,react-native,redux,react-router,react-redux,Reactjs,React Native,Redux,React Router,React Redux,我需要创建组件/文件/类任何内容,并将其连接到redux商店。 我不需要渲染此组件。 它只是一个助手组件,可以包含从存储返回值的方法。 我试图创建一个文件: export function getKeyFromReduxStore(key:string) {... 但这只是一个导出函数的文件,我无法(或不知道)如何将其连接到redux存储。 我的所有组件都通过存储连接: <RouterWithRedux> <Scene key="root">...

我需要创建
组件/文件/类
任何内容,并将其连接到redux商店。
我不需要渲染此组件。
它只是一个助手组件,可以包含从存储返回值的方法。
我试图创建一个文件:

export function getKeyFromReduxStore(key:string) {...
但这只是一个导出函数的文件,我无法(或不知道)如何将其连接到redux存储。
我的所有组件都通过存储连接:

<RouterWithRedux>
          <Scene key="root">...

...
但正如我所说,这不是场景,它只是我想在整个应用程序中重用的助手组件。

如何制作这样的组件并将其连接到redux?

redux存储有一个名为
getState
的方法,该方法获取存储的状态。您可以导入在需要redux存储的文件中创建的存储

//在创建存储的文件中
从“redux”导入{createStore};
export const myStore=createStore(
//…一些中间件或减速机等
)
//在组件/文件/类中
从“../path/to/store”导入{myStore}
导出函数getKeyFromReduxStore(键:字符串){
return(myStore.getState())[key];

}
Redux存储有一个名为
getState
的方法,该方法获取存储的状态。您可以导入在需要redux存储的文件中创建的存储

//在创建存储的文件中
从“redux”导入{createStore};
export const myStore=createStore(
//…一些中间件或减速机等
)
//在组件/文件/类中
从“../path/to/store”导入{myStore}
导出函数getKeyFromReduxStore(键:字符串){
return(myStore.getState())[key];
}