redux

How and where to save the whole redux store using AsyncStorage

心不动则不痛 提交于 2020-01-01 04:16:05
问题 I was wondering if I have to do something like this to save the whole store of my app using AsyncStorage in my react-native app and check if it exists when the app is starting. var store; _loadInitialState = async () => { try { var value = await AsyncStorage.getItem(STORAGE_KEY); if (value !== null){ store = value; console.log('Recovered selection from disk: ' + value); } else { store = configureStore({}); console.log('Initialized with no selection on disk.'); } } catch (error) { console.log(

Redux-form: display a list of errors on top of a page

痞子三分冷 提交于 2020-01-01 01:45:10
问题 I want to use Redux-form in a manner that changes input color & displays the actual error on top of the page. How do I access the list of current field errors outside the fields themselves? 回答1: You can't get the list of errors from outside of the render function given to the Field component. This is because errors are not stored in the redux store. EDIT 26/12/2018 : This answer is taking some age. ReduxForm now stores errors in the Redux store. Take a look to @nicoqh's answer which is using

React and Redux: redirect after action

五迷三道 提交于 2019-12-31 21:34:48
问题 I develop a website with React/Redux and I use a thunk middleware to call my API. My problem concerns redirections after actions. I really do not know how and where I can do the redirection: in my action, in the reducer, in my component, … ? My action looks like this: export function deleteItem(id) { return { [CALL_API]: { endpoint: `item/${id}`, method: 'DELETE', types: [DELETE_ITEM_REQUEST, DELETE_ITEM_SUCCESS, DELETE_ITEM_FAILURE] }, id }; } react-redux is already implemented on my website

Can I use redux-saga's es6 generators as onmessage listener for websockets or eventsource?

自闭症网瘾萝莉.ら 提交于 2019-12-31 21:33:10
问题 I'm trying to get redux-saga working with the onmessage listener. I don't know why what I have isn't working. I have the following set-up. // sagas.js import { take, put } from 'redux-saga'; import {transactions} from "./actions"; function* foo (txs) { console.log("yielding"); // appears in console yield put(transactions(txs)); // action *is not* dispatched console.log("yielded"); //appears in console } const onMessage = (event) => { const txs = JSON.parse(event.data); const iter = foo(txs);

Strongly typing the react-redux connect with typescript

蓝咒 提交于 2019-12-31 13:00:10
问题 I am getting an error trying to type the parameters for my react component. I would like to stronly type what properties will be on the props and state of a component, but when I do so using Redux, I am getting an error when I pass mapStateToProps to the connect function. This is the component code: import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import FileExplorer from '..

Dealing with local state in react and redux

老子叫甜甜 提交于 2019-12-31 10:29:26
问题 Is it OK to store local state in the state object when using react together with redux? Storing everything in the state tree via actions quickly becomes tedious. It feels that some state is relevant only for presentation/display of the app, rather than the logic. By presentation I mean animations/blinking, the expanded/contracted state of panels, the sorting criteria in tables and so on. 回答1: This is difficult to answer, because different people will classify different parts of a component as

Avoid re-rendering a big list of items with react-redux

回眸只為那壹抹淺笑 提交于 2019-12-31 08:39:45
问题 I am using redux with react and typescript for my application. I am working with many items used at different places of my app. My state looks like this: { items: {42: {}, 53: {}, ... }, //A large dictionary of items itemPage1: { itemsId: [ 42, 34, 4 ], ... }, itemPage2: { ... }, ... } The user can modify some attributes of the items dispatching some actions. When this happen I need to redraw the components that have been modified in each pages. The issue is that my items are quite big and I

Passing props to react-redux container component

一世执手 提交于 2019-12-31 08:10:18
问题 I have a react-redux container component that is created within a React Native Navigator component. I want to be able to pass the navigator as a prop to this container component so that after a button is pressed inside its presentational component, it can push an object onto the navigator stack. I want to do this without needing to hand write all the boilerplate code that the react-redux container component gives me (and also not miss out on all the optimisations that react-redux would give

Passing props to react-redux container component

时间秒杀一切 提交于 2019-12-31 08:10:12
问题 I have a react-redux container component that is created within a React Native Navigator component. I want to be able to pass the navigator as a prop to this container component so that after a button is pressed inside its presentational component, it can push an object onto the navigator stack. I want to do this without needing to hand write all the boilerplate code that the react-redux container component gives me (and also not miss out on all the optimisations that react-redux would give

Add Custom createMaterialTopTabNavigator to component?

我只是一个虾纸丫 提交于 2019-12-31 07:06:09
问题 I have an issue with createMaterialTopTabNavigator, I'm already declaring an AppContainer in my Route.js File, the error goes away if create a separate AppContainer for a TobTab in a screen I want to add these Tob Tabs in like this const Root = createAppContainer(NavTabs); so I made a specific file contained a Tabs "NavTabs.js" import { createMaterialTopTabNavigator } from "react-navigation"; import AboutScreen from "./About"; import GalaryScreen from "./Galary"; import ReviewsScreen from ".