react-redux

Props not displaying from fetch call

﹥>﹥吖頭↗ 提交于 2021-01-28 21:12:15
问题 I am trying to display recipes and not sure if I have this setup correctly. I am pulling recipes from a rails api via get fetch request. At the moment nothing is displaying. Here is my recipe container: import React, { Component } from 'react' import RecipeList from '../components/RecipeList' import RecipeInput from '../components/RecipeInput' import { connect } from 'react-redux' import { postRecipes } from '../actions/postRecipes.js' import { getRecipes } from '../actions/getRecipes' class

Child component in react prevents parent component from importing redux store

允我心安 提交于 2021-01-28 11:15:46
问题 I have two react components which work independently of each other but when connected seem to break the core of my program. My setup is this: Redux store --> MusicList.js(first component) --> AppNavbar.js(second component inside MusicList.js). Independently the redux store works perfectly with the first component, but when I connect my second component to MusicList.js it breaks the importation of my store. There is also a third component "Items.js" which is connected to MusicList.js in the

How to Write A Typed Action Without Parameters

断了今生、忘了曾经 提交于 2021-01-28 09:38:15
问题 A Github issue suggests that we can use TypedAction.defineWithoutPayload for this purpose but I couldn't find any relevant examples on how to do so. I use this for login when an accessToken is being stored in the payload. If the token is present, the user gets access to private pages. export const login = (token: string) => typedAction("LOGIN", token); Now, on the logout button, I am trying to implement an action that removes the stored value in the payload. In this case, there will be no

React Redux sync action returns some Proxy object instead of string

一笑奈何 提交于 2021-01-28 09:01:57
问题 I have an input with currentAnswer : <input value={props.currentAnswer} onChange={(text) => dispatch(onChangeAnswer(text))} /> Which calls function onChangeAnswer : export function onChangeAnswer(text) { console.log(text); return { type: ON_CHANGE_ANSWER, data: text }; } Reducer: export default function reduce(state = initialState, action) { switch (action.type) { case ON_CHANGE_ANSWER: return assign({}, state, { currentAnswer: action.data }); Async actions works good, but when I change text

What is the meaning of actions and action types in React-redux?

孤街醉人 提交于 2021-01-28 08:33:55
问题 Now if i want to change value in store i should do following steps: Go to constants/actionTypes file, create a line with action type Go to actions and create action function In each component where i use it i should create a function for mapDispatchToProps In reducer i should write a logic of changing Whats the point of such complexity? Will it be wrong if i will do just one file with actions which will change the state? For example: // actions.js export const setCategories = (payload,

Change Language as a user preferance in React Native App

给你一囗甜甜゛ 提交于 2021-01-28 08:11:47
问题 I am creating an app using React Native and need the ability to change the app's language "on the fly" so to speak. I have followed the sample here: https://github.com/appfoundry/react-native-multi-language-sample. After following this I have successfully setup Redux and all of the accompanying libraries. The issue I'm having is that I'm trying to trigger my action from an alert popup not a picker and I'm having issues actually dispatching the action. If anyone can show me how to change the

React redux and React router,link change does not re render view [duplicate]

十年热恋 提交于 2021-01-28 07:29:38
问题 This question already has answers here : React router changes url but not view (22 answers) Closed 2 years ago . I a few <Link/> elements and a few corresponding components that are rendered via the <Route/> The components that are being rendered by <Route/> are redux connect -ed. On clicking the links,the url in the address bar changes but not the rendered component view. However,the proper view is rendered on refreshing. Code for the container component(the one with the Routers and Links)

Get wrapped component class from connected HOC in react-redux

懵懂的女人 提交于 2021-01-28 06:58:06
问题 When using the connect function in react-redux , a Higher Order Component is created. From an instance of that HOC, one can access the wrapped instance of the extended component. Is it possible, however, to retrieve the wrapped class from the HOC class? E.g.: class A extends React.Component {} ConnectedA = connect(mapStateToProps, mapDispatch)(A); ConnectedA.some_static_method_to_get_the_wrapped_class(); // === A EDIT: For the sake of clarity, I do not have an instance of ConnectedA available

Redux Connect w/ HOC - TypeError: Cannot set property 'props' of undefined

拜拜、爱过 提交于 2021-01-28 02:18:00
问题 I'm building a quick authentication higher order component in Next.js and am getting some problems with the following code: import SignIn from "../components/sign-in"; import { connect } from "react-redux"; import { useRouter } from "next/router"; const AuthenticationCheck = WrappedComponent => { const { isAuthenticated, ...rest } = props; const router = useRouter(); const protectedPages = ["/colours", "/components"]; const pageProtected = protectedPages.includes(router.pathname); return

Difference between `Provider` and `connect` in Redux for React

ぃ、小莉子 提交于 2021-01-27 18:12:15
问题 I see that with Redux there's two ways of passing down the state to the components in a React app, one is throw the Provider component and the other one with the connect functionality. However, I wonder why there's two different ways and which one is better in performance than the other. 回答1: They are not mutually exclusive. Actually you will almost always need to use Provider , even with connect (See: https://github.com/reactjs/react-redux/blob/master/docs/api.md#provider-store) Without