react-redux

Converting functions from pure react to redux react

情到浓时终转凉″ 提交于 2021-02-07 18:21:36
问题 In pure react, I have written a function that I call in componentDidMount () : getTasks = (userId, query, statusTask, pageNumber) => { let check = {}; axios({ url: `/api/v1/beta/${userId}`, method: 'GET' }) .then(res => { check = res.data; if (res.data) { this.setState({ checkRunning: res.data, checkRunningId: res.data.id }); this.utilizeTimes(res.data.task_id); } }) .catch(error => { console.log(error); }) .then(() => { const params = { sort: 'name' }; if (query) { params['filter[qwp]'] =

Converting functions from pure react to redux react

落花浮王杯 提交于 2021-02-07 18:21:29
问题 In pure react, I have written a function that I call in componentDidMount () : getTasks = (userId, query, statusTask, pageNumber) => { let check = {}; axios({ url: `/api/v1/beta/${userId}`, method: 'GET' }) .then(res => { check = res.data; if (res.data) { this.setState({ checkRunning: res.data, checkRunningId: res.data.id }); this.utilizeTimes(res.data.task_id); } }) .catch(error => { console.log(error); }) .then(() => { const params = { sort: 'name' }; if (query) { params['filter[qwp]'] =

Redux thunk - how to prevent it from making unnecessary API request?

≯℡__Kan透↙ 提交于 2021-02-07 17:26:35
问题 I have action.js file like this: import axios from 'axios'; export const SEARCH_TERM = 'SEARCH_TERM'; export const SAVE_SEARCH = 'SAVE_SEARCH'; export function search(query) { const githubApi = `https://api.github.com/search/repositories?q=${query}&sort=stars&order=desc`; const request = axios.get(githubApi); return (dispatch) => { request.then(({ data: dataFromGithub }) => { dispatch({ type: SEARCH_TERM, payload: query }); dispatch({ type: SAVE_SEARCH, payloadOne: query, payloadTwo:

Redux thunk - how to prevent it from making unnecessary API request?

↘锁芯ラ 提交于 2021-02-07 17:25:31
问题 I have action.js file like this: import axios from 'axios'; export const SEARCH_TERM = 'SEARCH_TERM'; export const SAVE_SEARCH = 'SAVE_SEARCH'; export function search(query) { const githubApi = `https://api.github.com/search/repositories?q=${query}&sort=stars&order=desc`; const request = axios.get(githubApi); return (dispatch) => { request.then(({ data: dataFromGithub }) => { dispatch({ type: SEARCH_TERM, payload: query }); dispatch({ type: SAVE_SEARCH, payloadOne: query, payloadTwo:

Deleting individual items from react-beautiful-dnd horizontal list

谁说胖子不能爱 提交于 2021-02-07 10:13:40
问题 I have react-beautiful-dnd horizontal multiple list(6 rows with the same items in each row) with the same items in each list. I want to delete individual selected items from each list, but just having a button component with onClick fires the onClick while rendering the lists itself. How do i configure the list so that an individual item is deleted from that list when i click on the close/delete (x) button? Below, is my code, import React, { Component } from 'react'; import { DragDropContext,

pass props in tabs in react native

て烟熏妆下的殇ゞ 提交于 2021-02-05 12:29:37
问题 I would like to know how to pass a state from my main page to the Tabs? Currently I'm using navigate to transfer props from one page to another page but from Tabs it seems I cannot do that, do you have a function or sample code on how to pass props to the Tabs? 回答1: Simply Pass the state as props like this: <SampleComponent sampleProps={this.state.MyMainPageState} /> from there you can access it at your SampleComponent as props ;) inside SampleComponent you can try logging it: //this is the

Redux / RTK: create enhancer for one slice?

有些话、适合烂在心里 提交于 2021-02-05 11:57:16
问题 In one of the slices in my Redux / RTK store, all I need to to do to make the slice do its job is to create an entity adapter using createEntityAdapter() and export the setAll CRUD function. So far, so simple - thanks to RTK :-) However, when data for that slice comes in, I need to "augment" it (or "enhance" it, as Redux docs call it), i.e. add further information derived from data coming in, for example for formatted data displayde in the UI (contrived example). I created an enhancer for

Redux / RTK: create enhancer for one slice?

孤者浪人 提交于 2021-02-05 11:57:05
问题 In one of the slices in my Redux / RTK store, all I need to to do to make the slice do its job is to create an entity adapter using createEntityAdapter() and export the setAll CRUD function. So far, so simple - thanks to RTK :-) However, when data for that slice comes in, I need to "augment" it (or "enhance" it, as Redux docs call it), i.e. add further information derived from data coming in, for example for formatted data displayde in the UI (contrived example). I created an enhancer for

How can I create a “global state” in react native so I can send a user input to another page?

喜你入骨 提交于 2021-02-05 11:14:06
问题 I am trying to take a user input(email) and send it to the password page for display. I am under impression by attempt below is not working because the input is local and cannot be seen by the password page? How should I go about this? Something with reduxes? Am I on the right track? If you guys need more code let me know, I appreciate any help more than you know! Email page constructor() { super(); this.state = { color1: '#A2A2A2', inputValue: '', //add state here }; } updateInputValue =

How do I deal with “Cannot read property 'map' of undefined” react/redux

牧云@^-^@ 提交于 2021-02-05 11:13:20
问题 Once again, I'm facing a very common mistake "Cannot read property 'map' of undefined" . I have a initial list of items (movies) loading properly inside a <ul><li></li></ul> . However after dispatching my action by clicking my button, the error happen. I can actually see the state updated in my redux dev tool (even with the error) but I also can see that the change doesn't impact my store state in my react dev tool. So here is my reducer : export default function moviesReducer(state = {items}