├── .gitignore ├── README.md ├── index.js ├── package-lock.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | node_modules 3 | *.log -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # use-redux-hook 2 | 3 | [![npm version](https://badge.fury.io/js/use-redux-hook.svg)](https://badge.fury.io/js/use-redux-hook) 4 | 5 | **A simple react hook to get access to redux store** 6 | 7 | # Pre-requisite 8 | 9 | **Needs:** 10 | 11 | - react > 16.8, 12 | - react-redux > 6.0.0 13 | 14 | # Use cases 15 | 16 | Currently only way to get access to redux is via the connect HOC. There is no clean way to do it the hook way. 17 | This module is a tiny hook that gives out redux store 18 | 19 | # Install 20 | 21 | ``` 22 | npm install use-redux-hook 23 | ``` 24 | 25 | or 26 | 27 | ``` 28 | yarn add use-redux-hook 29 | ``` 30 | 31 | # Usage 32 | 33 | ### Basic 34 | 35 | **Simple use case** 36 | 37 | ```js 38 | import React from "react"; 39 | import { useReduxStore } from "use-redux-hook"; 40 | 41 | export const ExampleReactComponent = () => { 42 | const {getState, dispatch} = useReduxStore(); 43 | const { user } = getState(); 44 | return
Hello {user.name}
; 45 | }; 46 | ``` 47 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import { useContext } from "react"; 2 | import { ReactReduxContext } from "react-redux"; 3 | 4 | export const useReduxStore = () => { 5 | const { store } = useContext(ReactReduxContext); 6 | return store; 7 | }; 8 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "use-redux-hook", 3 | "version": "1.0.2", 4 | "lockfileVersion": 1 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "use-redux-hook", 3 | "version": "1.0.2", 4 | "description": "A react hook to get redux store", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "react-hook", 11 | "redux", 12 | "hook", 13 | "react", 14 | "dispatch" 15 | ], 16 | "author": "atulanand94@gmail.com", 17 | "license": "MIT", 18 | "peerDependencies": { 19 | "react": ">=16.8.0", 20 | "react-redux": ">=6.0.0" 21 | } 22 | } 23 | --------------------------------------------------------------------------------