Today, we want to go over to our src/ folder and create a new file sagas.js.
TODO #1: Create src/sagas.js file, or better yet go sign up for our mailing list and download sagas.js because the file is about 500 LOC! You won't be able to continue without this file.
Redux saga, you can read the description in the link, or you can read the dumb-down version (my version 😉):
Imagine we have one thread responsible for running our application. Redux saga just spins up another thread that can read the store, much like the main thread. When we call a function to fetch data from the API, we actually spin off a different thread - this thread will go call the API with the parameters, wait for a response/error, and call the actions and reducers that'll update the store with the response/error.
yield call: Makes the call to the api with endpoint (api.loginUser) and the parameters (action.user_data)
storeTokens(): Function to take the response from login/signup to save the tokens.
yield put: Calls the actions to call the reducer to update the data in the store with the response data.
NavigationService.navigate('Profile'): A function that'll allow us to navigate the user to their profile after successful signup/login.
The FirebaseAuthToken is assigned by google. And, the two tokens, FirebaseAuthToken and the Auth are there to tell us that the user is authenticated.
That's all for today, remember to go join our mailing list to get sagas.js.
Our medium post for this article: / react-native-tutorial-step-15
Don't forget to like, comment, and subscribe!!!
========================================================
Reference Links
========================================================
Redux saga: https://github.com/redux-saga/redux-saga
========================================================
Connect with me!
========================================================
Linkedin: / donaldlee50
Instagram: / donlee50
Twitter: / donaldlee50
Youtube: / coursehack
Mailing List: http://bit.ly/coursehack-mailing-list
Coursehack's Facebook Group: bit.ly/join-coursehack-facebook-group
Don't forget to like, comment, and subscribe!