redux-thunk

correct way to use firestore onSnapShot with react redux

烈酒焚心 提交于 2020-08-21 07:02:08
问题 I'm trying to figure out the correct way to use firestore.onSnapshot with react-redux. I currently have this code in my action file, which I am calling on componentWillMount() in my component. export const fetchCheckins = () => async (dispatch) => { const {currentUser} = firebaseService.auth(); try { let timestamp = (new Date()); //set timestamp for beginning of today timestamp.setHours(0); //get checkins today let checkinstoday = (await firebaseService.firestore().collection(`/checkins/$

correct way to use firestore onSnapShot with react redux

╄→尐↘猪︶ㄣ 提交于 2020-08-21 07:01:46
问题 I'm trying to figure out the correct way to use firestore.onSnapshot with react-redux. I currently have this code in my action file, which I am calling on componentWillMount() in my component. export const fetchCheckins = () => async (dispatch) => { const {currentUser} = firebaseService.auth(); try { let timestamp = (new Date()); //set timestamp for beginning of today timestamp.setHours(0); //get checkins today let checkinstoday = (await firebaseService.firestore().collection(`/checkins/$

Redux-Toolkit createAsyncThunk Dispatch is showing as undefined

戏子无情 提交于 2020-07-10 07:01:19
问题 Using Redux-Toolkit, I am trying to use ThunkAPI & dispatch inside an createAsyncThunk but I am getting rejected because of type error. Not sure how to resolve this. my store: export const store = configureStore({ reducer: rootReducer, middleware: [...getDefaultMiddleware()], }); my Action: export const tester = createAsyncThunk( 'tester', async (testData, {dispatch}) => { await dispatch(load(true)); const final = await someExternalFunc(testData) return final; } ); but, I am getting output as

redux-thunk and in app architecture - want to render only views in views and dispatch GET actions in separate component

纵然是瞬间 提交于 2020-07-09 12:48:12
问题 I am using react-redux and redux-thunk in my application and there are two things I am trying to do: I want to be able to share the results of a GET request in two components. I know you can do this by connecting the two components to the store, but I want to make it so if the user lands on X page, then Y page cannot make the same GET request again (these two components are Thumbnail and Carousel). In other words, the GET request should be made once (not 100% sure what best practice is here

How to make a post request using react redux?

…衆ロ難τιáo~ 提交于 2020-06-26 06:01:21
问题 I have created a form with email, firstname, lastname details. Now I want to make a POST request to localhost:5000/api/users and want to store it in mongo database. How can I make use of redux ? I have implemented it using on reactjs only how can I make use of redux ? Note: I am using redux thunk. Code: login.js: import React, { Component } from 'react' import './login.css' export default class Login extends Component { constructor(props) { super(props) this.state = { firstName:'', lastName:'

Call function after dispatch from redux has finished

南楼画角 提交于 2020-06-24 07:28:06
问题 All around it but not quite as I have enough of an idea of redux-thunk and of react-router but I am not getting this seemingly simple idea of: Call a change in route programmatically via <Route/> 's history.push('/') after an action has finished dispatching to the store, this to happen when a button is pushed. const LoggerRedux = ({stateProp, LogIn}) => { return( <div> <h2>Here is the button. Use this to login</h2> <Route render={({ history}) => ( <button type='button' onClick={ //Something

How do I resolve 'Property 'type' is missing in type 'AsyncThunkAction' using Redux Toolkit (with TypeScript)?

爷,独闯天下 提交于 2020-06-17 15:49:09
问题 I'm using Redux Toolkit with the thunk/slice below. Rather than set the errors in state, I figure I could just handle them locally by waiting for the thunk promise to resolve, using the example provided here. I guess I could avoid doing this, and perhaps I should, by setting an error in the state but I sort of want to understand where I went wrong on this. Argument of type 'AsyncThunkAction<LoginResponse, LoginFormData, {}>' is not assignable to parameter of type 'Action<unknown>'. Property

Redirect page upon login using react-router-v5 and redux-toolkit

橙三吉。 提交于 2020-06-11 15:11:53
问题 I'm using react-router-dom v5.2. Upon login, I want my page to redirect to /home from / . The login form is at / . When I try to perform authentication without any async function (ie. comparing username and password to hardcoded values in react), everything works perfectly. But when I do perform authentication using express and mongo, the redirection upon login stops working. If I login again, then the redirection happens. Protected routes still work (redirect to login page if the user is not

Redirect page upon login using react-router-v5 and redux-toolkit

允我心安 提交于 2020-06-11 15:11:03
问题 I'm using react-router-dom v5.2. Upon login, I want my page to redirect to /home from / . The login form is at / . When I try to perform authentication without any async function (ie. comparing username and password to hardcoded values in react), everything works perfectly. But when I do perform authentication using express and mongo, the redirection upon login stops working. If I login again, then the redirection happens. Protected routes still work (redirect to login page if the user is not