react-redux

React Redux Persist is rehydrating, but no stored data is retrieved, instead, default

馋奶兔 提交于 2020-12-15 08:55:41
问题 I've been struggling with this problem for two days, so I need help! I have a React web in wich i've added Redux Persist (also Redux Saga for handling requests) as the documentation said. I'm testing with a store that doesn't have any saga in the middle, when I trigger an action, the data is updated, I can see it in the Debugger, but when i refresh, despite the Redux Hydrate process runs, that value goes back to the default one. store.js import { createStore, applyMiddleware, compose } from

React Redux Persist is rehydrating, but no stored data is retrieved, instead, default

若如初见. 提交于 2020-12-15 08:53:16
问题 I've been struggling with this problem for two days, so I need help! I have a React web in wich i've added Redux Persist (also Redux Saga for handling requests) as the documentation said. I'm testing with a store that doesn't have any saga in the middle, when I trigger an action, the data is updated, I can see it in the Debugger, but when i refresh, despite the Redux Hydrate process runs, that value goes back to the default one. store.js import { createStore, applyMiddleware, compose } from

Testing react app with jest and enzyme token problem

谁都会走 提交于 2020-12-15 07:19:40
问题 I have a react app in which I have added unit testing, but one of my tests fails, Here is my test file, I want to test action creators getUser . When I run npm test I get the following error, FAIL UnitTests resources/js/tests/actions/index.test.js ● Test suite failed to run TypeError: Cannot read property 'getAttribute' of null 8 | 'Accept': 'application/json', 9 | 'Content-Type': 'application/json', > 10 | 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute(

Testing react app with jest and enzyme token problem

偶尔善良 提交于 2020-12-15 07:19:16
问题 I have a react app in which I have added unit testing, but one of my tests fails, Here is my test file, I want to test action creators getUser . When I run npm test I get the following error, FAIL UnitTests resources/js/tests/actions/index.test.js ● Test suite failed to run TypeError: Cannot read property 'getAttribute' of null 8 | 'Accept': 'application/json', 9 | 'Content-Type': 'application/json', > 10 | 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute(

How to store and retrieve objects in react-redux? [Objects subscribed to local-storage]

梦想与她 提交于 2020-12-15 05:20:53
问题 I have a reducer like this: const UserReducer = (state=JSON.parse(localStorage.getItem('user')), action) => { switch(action.type){ default: return state; case "REFRESH_AUTH": return state = JSON.parse(JSON.stringify(action.payload.user)); case "CLEAR_AUTH": return state = null; } } I need to store an object here, and hence I need to stringify it before saving it. Now, though, when I reload the page and the reducer tries to get JSON.parse(localStorage.getItem('user')) I get this error:

How to store and retrieve objects in react-redux? [Objects subscribed to local-storage]

偶尔善良 提交于 2020-12-15 05:20:48
问题 I have a reducer like this: const UserReducer = (state=JSON.parse(localStorage.getItem('user')), action) => { switch(action.type){ default: return state; case "REFRESH_AUTH": return state = JSON.parse(JSON.stringify(action.payload.user)); case "CLEAR_AUTH": return state = null; } } I need to store an object here, and hence I need to stringify it before saving it. Now, though, when I reload the page and the reducer tries to get JSON.parse(localStorage.getItem('user')) I get this error:

axios.get() is combining the url when sending requests to the backend.

纵然是瞬间 提交于 2020-12-13 07:52:08
问题 I'm sending a request to the backend via axios calls the URL on my address bar is "localhost:3000/topics/5ba06e74dbc" but in my browser inspector its returning an error "localhost:3000/topics/api/topics/5ba06e74dbc 404 (Not Found)" the request should be: "localhost:3000/api/topics/5ba06e74dbc" anyone know why that extra "topics/" is being added in front of the api call? // my action call I suspect it might be because of my routes or because //Im calling from topics/ already. export const

How to avoid “Excessive number of pending callbacks: 501” error during images download in React Native?

我与影子孤独终老i 提交于 2020-12-13 04:35:05
问题 I need to download a collection of images on button press. Currently, I'm doing it this way using react-native-fs : const downloadImageItem = async (imgUrl, id) => { const path = `${RNFS.DocumentDirectoryPath}/${id}.jpg`; RNFS.downloadFile({ fromUrl: imgUrl, toFile: path, }); }; const downloadImages = async (items) => { for (const item of items) { if (item.images.length) { await downloadImageItem(item.images[0].thumb, item.images[0].id); } } return Promise.resolve(); }; Calling the function

React - Axios call make too many requests

旧街凉风 提交于 2020-12-12 05:09:30
问题 Im learning React & Redux by making a game project. I want to fetch data (attributes) by API, but it cause too many requests. Guess it can be realted to placing axios call directly in functional react component, but i have no idea how to fix it. function Attributes({ attributes, dispatch }) { axios.get(`/api/heroes/1/get-attributes`).then(res => { dispatch(AttribAction.set(objectToArray(res.data))); }); return ( <div className="content"> {attributes.map((attrib, index) => ( <div key={index}

React-redux useDispatch() Uncaught TypeError

一世执手 提交于 2020-12-11 17:52:05
问题 I'm trying to create a simple component to dispatch an action using the React Redux hook useDispatch - and I'm getting an error. I've trimmed the component down to where the error occurs. It happens when the useDispatch function is called. import { useDispatch } from 'react-redux' const MyComp = () => { useDispatch() return null } export default MyComp This is the error I'm seeing in dev console: Uncaught TypeError: Object(...) is not a function at MyComp (MyComp.js?cc4c:4) at renderWithHooks