# How-Which library to use for React-Redux

**URL:** <https://community.auth0.com/t/how-which-library-to-use-for-react-redux/55854>\
**Category:** Get Help\
**Tags:** jwt, api, react, redux, auth0\
**Created:** [January 8, 2021, 12:17am UTC](https://community.auth0.com/t/how-which-library-to-use-for-react-redux/55854 "2021-01-08T00:17:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tzypo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/tzypo/32/26150_2.png) [@Tzypo](https://community.auth0.com/u/Tzypo)\
**Post date:** [January 8, 2021, 12:17am UTC](https://community.auth0.com/t/how-which-library-to-use-for-react-redux/55854/1 "2021-01-08T00:17:06Z")

</div>

I’ve a small react app which makes calls to an api using JWT bearer tokens.  
As I read auth0/auth0-react is the current SDK which we should use.  
This workred fine for me.  
I used this pattern to fetch data

> const { getAccessTokenSilently } = useAuth0();
> 
> useEffect(() =\> {
> 
> ```
> const load = async () => {
> const token = await getAccessTokenSilently();
> const response = await client.GetData(token);
> setData(response)
> }
> load();
> }, []);
> 
> ```

Now I migrated to react-redux.

Now I have an action which should get data from the api. But as the code doesn’t run in a hook I can’t use useAuth0()

```
export const fetchMyTrainees = () => {
    return async (dispatch: Dispatch) => {
        const { getAccessTokenSilently } = useAuth0();
        const token = await getAccessTokenSilently();
        const client: TraineesClient = traineesClientFactory(token);
        const trainees = await client.getMyTrainees();
        dispatch({
            type: TRAINEE_FETCH
            payload: trainees
        })
};

```

So should I have to move away from auth0-react? and what is the intended way to solve this?  
I could pass the token as a parameter but then each caller would have to do the token creation by themself which doesn’t seem good to me like described here: [useAuth0() hook with React + Redux App](https://community.auth0.com/t/useauth0-hook-with-react-redux-app/51433) or is this the way to go?

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [January 8, 2021, 5:35pm UTC](https://community.auth0.com/t/how-which-library-to-use-for-react-redux/55854/3 "2021-01-08T17:35:00Z")

</div>

Hi @Tzypo,

> [@Tzypo](#):
>
> I could pass the token as a parameter but then each caller would have to do the token creation…

If you want to continue to use the `auth0-react` SDK, you could pass the token to the action by using `useAuth0` or `withAuth0`, but I agree that you probably want to handle that within the action instead of each component since you are using Redux.

The `auth0-react` SDK is built on top of the [Single Page App SDK](https://auth0.com/docs/libraries/auth0-single-page-app-sdk). Since you don’t want to use the React wrapper for hooks and components, you may want to use `auth0/auth0-spa-js` instead.

This topic shows an example of using `auth0/auth0-spa-js` and moving the auth0client outside of the Auth0 Provider so that actions are : [Using @auth0/auth0-spa-js outside of a React Component - #4 by klequis](https://community.auth0.com/t/using-auth0-auth0-spa-js-outside-of-a-react-component/27805/4)

Here are some additional resources you may find helpful for securing React/Redux apps:

- [Secure Your React and Redux App with JWT Authentication](https://auth0.com/blog/secure-your-react-and-redux-app-with-jwt-authentication)
- [Beyond Create React App: React Router, Redux, Redux Saga, and More](https://auth0.com/blog/beyond-create-react-app-react-router-redux-saga-and-more)
- [Redux: A Practical Tutorial](https://auth0.com/blog/redux-practical-tutorial)
- [Beyond Create React App: React Router, Redux Saga, and More](https://community.auth0.com/t/beyond-create-react-app-react-router-redux-saga-and-more/23118)
- [Up to date Redux example](https://community.auth0.com/t/up-to-date-redux-example/27728)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 23, 2021, 5:35pm UTC](https://community.auth0.com/t/how-which-library-to-use-for-react-redux/55854/4 "2021-01-23T17:35:01Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
