react-redux

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 }; /

React Native Calendars : How to change the background color of only one item using Redux

吃可爱长大的小学妹 提交于 2021-01-29 11:07:13
问题 I'm trying to change the background of only one item in this agenda but with my code, when I click on an item, it changes the background color of all of them and not just the one I clicked : Before clicked after clicked. I want also to store the value of my state in redux so that I can display the screen elsewhere in my application while conserving the green color. Here is my code from my calendar: import React, {useState, useCallback, useEffect} from 'react'; import { Text, View,

Element type invalid: expected a string or a class function

走远了吗. 提交于 2021-01-29 10:15:57
问题 I am new to react was trying to implement CRUD operations in React JS using web api. However, I am receiving an error which I do not understand. The error is this: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. ▶ 20 stack frames were collapsed. Module../src/index.js D:/crud

Assign resolve function from Promise to a variable

孤人 提交于 2021-01-29 10:06:55
问题 There's a snippet of code that I cannot seem to understand. There's a function that is declare empty at first: let dCredentials = (credentials: any) => {} Then this variable is later reasignned in a function later called: return new Promise((resolve, _) => (dispatchCredentials = resolve)) What does the second code do? Does it return anything after someone uses .then in the promise? 回答1: If you get a reference to the resolve function to outside the promise, then you can resolve it at any point

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" :

How to execute multiple generators based on actions dispatched asynchronously

99封情书 提交于 2021-01-29 08:42:28
问题 I am trying to dispatch multiple actions which will trigger multiple generator functions. OnClick dispatch({ type: "ACTION_1", data1}); dispatch({ type: "ACTION_2", data2}); saga.js function* method1(action){ //... const response = yield call(api, requestParams); //... } function* method2(action){ //... const response1 = yield call(api, requestParams1); //... //dependent on response1 const response2 = yield call(api, requestParams2); //... //dependent on response2 const response3 = yield call

React Native Updating State with Api

馋奶兔 提交于 2021-01-29 08:25:17
问题 0 Hi I'm trying to update the state data value (data:[]) from API. the issue is from the line highlighted this.setState({data.datasets[0].data.data:response.data.rates.AUD}) import React from 'react'; import {Bar} from 'react-chartjs-2'; import axios from 'axios'; class App extends React.Component { constructor(props) { super(props) this.state = { data: { labels:["UK"], datasets:[ {label:"Dev Test",data:[]} ] }} this.test = this.test.bind(this) } async test() { const response = await axios

React Redux double mount with useEffect cleanup of previous component

时光怂恿深爱的人放手 提交于 2021-01-29 06:13:54
问题 I'm using react-redux, and I'm trying to clear part of my redux state when a component unmounts, this actually does work, but the problem is that once userProfile is cleared and next component mounts it is unmounted and then mounted again. useEffect(() => { getProfileByUsername(match.params.username, user && user.id); return () => clearUserProfile(); }, [match.params.username]) I can see my clear action is being called before any mount of the next component occurs, but the data is not cleared

How can I return immutable data from redux reducer?

时光总嘲笑我的痴心妄想 提交于 2021-01-29 06:12:56
问题 For a learning and test project, I'm trying to return immutable redux data from reducer because safe data for component. this is my reducer code : function itemsReducer(state = [], action) { switch(action.type) { case 'ITEMS': return [...action.data] default: return state } } And this is my loop code : <ul> { this.props.items.map((item) => ( <li>{item.name.first} {item.name.last}</li> )) } </ul> now every things work right, but after change on props with this method : change() { this.props

React Native - [Unhandled promise rejection: Error: Signup Error]

我的梦境 提交于 2021-01-29 05:17:26
问题 I get this intentional error because I'm using the same email to register. It says I'm not handling the rejection; can someone explain why because I have a .catch() which should catch any errors that were thrown Error code: [Unhandled promise rejection: Error: Signup Error] - node_modules\promise\setimmediate\core.js:37:14 in tryCallOne - node_modules\promise\setimmediate\core.js:123:25 in setImmediate$argument_0 - node_modules\react-native\Libraries\Core\Timers\JSTimers.js:146:14 in