redux

Cannot destructure property `user` of 'undefined' or 'null'

∥☆過路亽.° 提交于 2021-01-29 13:10:39
问题 Error retrieving user information with redux. I want to get the user information (name, password and address of the avatar from the db) and then edit it. I'm using nodejs, express, react, redux and jwt. Actions/user.js import axios from 'axios'; import {setAlert} from './alert'; import {GET_USER, USER_ERROR} from './types'; //Get current users profile export const getCurrentUser = () => async dispatch => { try { const res = await axios.get('/api/users/me'); dispatch({ type: GET_USER, payload:

MERN: Added a User object to another Model's array, prevented duplicate additions, but now it prevents OTHER users too

自古美人都是妖i 提交于 2021-01-29 13:06:52
问题 My app has two Models. User and Tournament. User model has username and _id (mongodb). Tournament model has participants which is an Array. I'm trying to make it so each and every user who signs up to a tournament can do so only once. I wrote an Express route to POST to a tournament's participants array: router.post('/:id', (req, res) => { Tournament.findById(req.params.id) .then(tournament => { const userSignedUp = (participantsArray, user) => { return participantsArray.some(arr => arr.user

How do you access the values from a redux form in a reducer?

北城以北 提交于 2021-01-29 11:57:51
问题 I am trying to get access from the redux form that is being filled out inside my reducer so I can replace the values of another object to an array. How do you properly submit and pass the values from a redux form? I have tried passing it back through the redux actions. I've tried accessing it in the reducer directly from the store because I figured that's where it's being stored. I feel like I am doing something simple wrong class EditWorkoutItem extends Component { state = { open: false }; /

Redux-form: update syncErrors cause form to skip modifications

青春壹個敷衍的年華 提交于 2021-01-29 10:51:47
问题 I have a checkbox in my redux-form and upon pressing the checkbox, it shows for a millisecond as if it unchecked it but then returned to previous checked state and only clicking checkbox the second time actually unchecks it. I looked into redux-dev-tools and it shows that after form CHANGE event, UPDATE_SYNC_ERRORS one follows. Here is some code that I have: const ProjectFamiliesFilterInput = React.memo(({ familyOptions, analysisGroupOptions, projectAnalysisGroupsByGuid, value, onChange, ..

Why reducer function return only proxy? redux/toolkit

喜夏-厌秋 提交于 2021-01-29 10:35:32
问题 My reducer function in state parameter (payload) returns the only proxy: Proxy {i: 0, A: {…}, P: false, I: false, D: {…}, …} [[Handler]]: null [[Target]]: null [[IsRevoked]]: true My slice where is state proxy: import { createSlice } from "@reduxjs/toolkit"; export const userSlice = createSlice({ name: "user", initialState: { currentUser: { loggined: false, isAdmin: false, jwt: false, }, }, reducers: { setUser: (state, payload) => { console.log(state); // here is problem, but payload works

Can't install service worker of workbox-webpack-plugin in root url for React app, it's installing at localhost:8080/dist

陌路散爱 提交于 2021-01-29 09:57:29
问题 I have been following a lot of tutorials of how to install workbox-webpack-plugin but I haven't succesfully managed to install it correctly. The service worker appears to be installing but its installing in the dist folder of my app (This is my webpacks output path). I think there's nothing wrong with this but when I run my app, there are no errors but the service worker is not functioning and I notice that it is being installed at localhost:8080/dist (The output path) and even if I try to

Redux dispatch in useEffect isn't syncronous

柔情痞子 提交于 2021-01-29 09:14:29
问题 I want to navigate to App screen or Auth screen, depending on the isUser prop after fetching it from the server and updating the redux store. My first component AuthLoading.js which looks like this: const AuthLoading = (props) => { const isUser = useSelector((state) => state.authReducer.isUserExists); const dispatch = useDispatch(); const fetchData = async () => { const token = await TokensHandler.getTokenFromDevice(); dispatch(isTokenExists(token)); props.navigation.navigate(isUser ? "App" :

Redux Toolkit - I can't update Slice state?

爱⌒轻易说出口 提交于 2021-01-29 08:58:33
问题 I wanna update the state and tried few ways to do that, but I can't. First, I got a problem with fetching state, as a result, I got proxy, not a state. That is fixed by the current() function by the redux toolkit. Next, where I have a problem is mutation main slice state. Here is a reducer for mutating. reducers: { setUser: (state, payload) => { console.log("before", current(state)); //init state state.currentUser = { ...state.currentUser, loggined: true, }; console.log("after", current(state

Type nested property state in array reduce Redux Typescript

送分小仙女□ 提交于 2021-01-29 08:45:31
问题 I'm having a problem with typing, particularly with the reduce() function, where accumulator[currentValue] returns an error: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'CombinedState<{ order: TOrderState; employee: TEmployeeState; }>'. No index signature with a parameter of type 'string' was found on type 'CombinedState<{ order: TOrderState; employee: TEmployeeState; }>'. interface TArgs { path: string[] action: Record<string, string>

TypeScript type of an async dispatch value

妖精的绣舞 提交于 2021-01-29 07:20:28
问题 I have the following async action definition: import {Dispatch} from 'react'; import axios, {AxiosResponse, AxiosError} from 'axios'; function asyncAction() { return (dispatch: Dispatch<any>): Promise<number> => { return axios.get('http://www.example.com') .then( (res: AxiosResponse<any>) => { return 1; }) .catch( (err: AxiosError<any>) => { return 2; }); } } The above typechecks fine. I also understand that when you call dispatch and pass it an asynchronous action, like so: dispatch