redux

Rewriting state in Redux

牧云@^-^@ 提交于 2019-12-22 11:10:19
问题 In redux I understand that state is immutable and when you create new state you are essentially updating the object with what ever new information there is and then totally rewriting the state. Today I had a thought and I am not sure how stupid it is. Is it computationally expensive to keep re-writing the state? I know that this is one of the major paradigms of Redux, but I want to know if this makes sense from a memory and space perspective. 回答1: You are allowed to mutate the state in Redux

Functional switch case with object literal and Typescript

好久不见. 提交于 2019-12-22 10:39:44
问题 So I've got this classic switch case redux reducer in a todomvc that I want to make functional but can't seem to wrap my head around ts typings for that. Switch case works great for pattern matching and narrows down action discriminated union by type. But I don't seem to get how to pass around narrowed actions with a functional approach where object literal's key should do a type narrowing. What I got so far is union type of all functions and some ts errors by the way. Would really appreciate

Redux state value globally

别来无恙 提交于 2019-12-22 10:34:24
问题 I am having a helper class which provies info about the logged in user. I would like to have it as a static method and use it in several places ( which are not react components) How to get access the redux store value in a class model ? 回答1: One way could be set a global variable window.store = createStore(...) and use it, accessing window.store 回答2: If you can manage this in your application it would be cleaner (and more testable) to pass it around with dependency injection (DI) as opposed

React Native - React Navigation slow transitions when nesting navigators

↘锁芯ラ 提交于 2019-12-22 10:28:14
问题 I am building a cross-platform native application using react-native and using react-navigation for navigating to and from screens and managing navigation state using redux. The problem arises when I am nesting my navigators. For example, I am using Stack Navigator as the default navigator for my app. export const DefaultNavigate = new StackNavigator( { Login: { screen: LoginScreen, }, Home: { screen: AppDrawerNavigate, }, AppTabNav: { screen: AppTabNavigator, }, } ); where my first screen is

React Native + AWS AppSync - maximum data storage

被刻印的时光 ゝ 提交于 2019-12-22 09:27:26
问题 I’m building an offline application which needs to store around 30,000 records. Will AWS AppSync have any performance issues with a data set of this size? I’ve used redux w/ redux-persist in the past, which saves the store offline, then refetchs and places in memory when the app launches. This causes fairly huge memory issues, especially when querying the data. I’m wondering if AppSync has the ability to use Realm or SQLite for offline storage and querying. Thanks. 来源: https://stackoverflow

How to use connect from react-redux [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-22 08:31:41
问题 This question already has answers here : How to get simple dispatch from this.props using connect w/ Redux? (3 answers) Closed 3 years ago . I'm having a little problem with connect(). I thought wrapping all components in Provider is going to work, but turns out it isn't.... So I found that I need to use connect() from react-redux. The problem is i don't know how should I use it. This site is showing some examples but, i don't have any action creators to put inside connect because I don't use

Update Multiple Properties of an object with spread operator

*爱你&永不变心* 提交于 2019-12-22 08:25:51
问题 I have a state in a reducer that looks like this: // The current source/selection const selection = { timespan: "-3660", customTimespan: false, pathIds: [''], source: undefined, direction: 0, appClassIds: [] }; What I want now is to update multiple properties (timespan and customTimeSpan), something like this (but this doesn't work): { ...state, { timespan: action.timespan.value, customTimespan: action.timespan.value } }; How can I update multiple properties of a state? 回答1: You need to

How to get updated data from apollo cache

空扰寡人 提交于 2019-12-22 08:17:46
问题 Does Apollo client have some sort of thing like mapStateToProps (Redux)? let's say I have a component, after query I know there's data in the cache so I do something like: class Container extends React.Component { ... ... render() { const notes = this.props.client.readFragment(NOTES_FRAGMENT) // notes has everything I need return (<Child notes={notes} />); } } export default WithApollo(Container); However when I have a sibling component which calls mutation and do update, the <Child />

How to dispatch redux action outside of a component?

夙愿已清 提交于 2019-12-22 08:10:04
问题 I'm using redux in my react-native mobile app. The communication with the backend is via websockets using socket.io . I organize the project in a way where I have a file (you could call it an object) which initialize the socket client. The handlers are registered to it, and I want to send actions to the reducers . socket.js : export function createSocket (url) { console.log(`connecting to ${url}`) // dispatch(actions.CONNECT) return io(url) } How can I dispatch actions from those functions

How to dispatch redux action outside of a component?

折月煮酒 提交于 2019-12-22 08:09:02
问题 I'm using redux in my react-native mobile app. The communication with the backend is via websockets using socket.io . I organize the project in a way where I have a file (you could call it an object) which initialize the socket client. The handlers are registered to it, and I want to send actions to the reducers . socket.js : export function createSocket (url) { console.log(`connecting to ${url}`) // dispatch(actions.CONNECT) return io(url) } How can I dispatch actions from those functions