redux

Is there a good way to preventDefault when dispatching an action in React/Redux?

非 Y 不嫁゛ 提交于 2019-12-23 18:39:42
问题 I'm dispatching an action that runs a reducer that pushes some text to my redux state on form submit. I know in Vue you can preventDefault right in the DOM but I haven't seen anything in React that would make this seem possible. I'm wondering the best way to prevent the form from submitting so Redux can do it's thing. My code is below. Thanks! actions/index.js export function addLink(text) { return { type: 'ADD_LINK', text } } reducers/index.js (ADD_LINK) is the function I'm running /*eslint

How can I use redux persist for only one reducer not for navigation reducer in my react native application?

谁说我不能喝 提交于 2019-12-23 17:50:51
问题 I am using Redux persist to persist my store for reducers. My application has two reducers Navigation and User Reducer.I want to persist only user state but I have to persist both states according to this syntax of redux persist. import {persistStore, autoRehydrate} from 'redux-persist' const store = createStore(reducer, undefined, autoRehydrate()) persistStore(store) the reducer that I have passed in the create store is the object of combine reducers. Problem: The problem I am getting

You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports

陌路散爱 提交于 2019-12-23 14:45:20
问题 import React from 'react'; import ReactDOM from 'react-dom'; import { createStore } from 'redux'; import createHistory from 'history/createBrowserHistory'; import { Provider } from 'react-redux'; import ConnectedRouter from 'react-router-redux'; import { Route, Switch } from 'react-router'; import Home from "./pages/Home"; import Register from "./pages/Register"; import CourseManagerDashboard from "./pages/CourseManagerDashboard"; import CourseDetail from "./pages/CourseDetail"; import App

How to dispatch a thunk from a saga?

与世无争的帅哥 提交于 2019-12-23 14:02:24
问题 I know I shouldn't be trying to dispatch thunks from sagas, it goes against what redux-saga tries to do. But I'm working in a fairly large app and most of the code is made with thunks, we are migrating by bits and need to dispatch a thunk from inside a saga. The thunk can't be changed because it is used in other parts (a thunk that returns a promise), so it would break many things. configureStore: const store = createStore( rootReducer, initialState, compose(applyMiddleware(thunk,

redux-thunk: Pause Component Execution Until Action Creator Completes

筅森魡賤 提交于 2019-12-23 12:00:03
问题 I've been struggling with this problem for several weeks now. I'm finally throwing in the towel and asking for help on this because I'm clearly not doing something right. I have a React.js app that is using redux and redux-thunk. I'm simply trying to get my Component Container to initiate the loading of data, but not render until the data comes back from the fetch request. Seems simple enough I know. Here is what I've done: Container Component 'use strict'; import React, { Component } from

React, Jest, Enzyme how to pass test App.js with store redux

淺唱寂寞╮ 提交于 2019-12-23 11:59:28
问题 Created a simple app using create-react-app then updated my App.js and added redux/store. class App extends Component { render() { return ( <header className="header"> <h1>todos</h1> </header> ); } } function mapStateToProps(state) { return { data: state.data }; } function mapDispatchToProps(dispatch) { return bindActionCreators(ActionCreators, dispatch); } export default connect(mapStateToProps, mapDispatchToProps)(App); then trying to test my App on App.test.js using Enzyme and Jest. import

typing redux store using flowtype and flow-typed

a 夏天 提交于 2019-12-23 10:48:16
问题 I'm trying to type the redux store like this : const s:Store<S,A>=createStore (todoApp) but I get identifier Store ... Could not resolve name flow error any idea how to fix this ? I am using this flow typed declarations: // flow-typed signature: ba132c96664f1a05288f3eb2272a3c35 // flow-typed version: c4bbd91cfc/redux_v3.x.x/flow_>=v0.33.x declare module 'redux' { /* S = State A = Action */ declare type Dispatch<A: { type: $Subtype<string> }> = (action: A) => A; declare type MiddlewareAPI<S, A

addEventListener react redux with mapped dispatch

安稳与你 提交于 2019-12-23 10:17:04
问题 I am currently trying to add an event listener to an application I'm making in react. I'm doing this by hooking into the componentDidMount API, which runs only once the component is rendered and not more than that. My problem is that I'm using connect from react-redux to bind my action creators to store.dispatch . I'm not sure how to bind the event listener to the version of the action creator that is bound to the store with dispatch. Is there a graceful way to do this? import React,

Stateless component React router

故事扮演 提交于 2019-12-23 09:57:57
问题 I am new to React and Redux, I am actually creating a code of myself but I got stuck with a router kind of thing inside stateless component. So, Actually I need to route to a component by using this.props.history.push('/somepath'). This is not happening inside a stateless component. My Stateless component is import React from "react"; // eslint-disable-line no-unused-vars import "bootstrap/dist/css/bootstrap.min.css"; import "./header.css"; const Header = () => ({ handleAuthor() { this.props

Redux NODE_ENV errors with Gulp/Browserify

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:28:05
问题 I'm getting this error message on a React/Redux app that is minified and packaged with Browserify and Gulp and deployed to Heroku. bundle.js:39 You are currently using minified code outside of NODE_ENV === 'production'. This means that you are running a slower development build of Redux. But it seems the build step is being done in NODE_ENV = 'production' . I've a task that set the env variables like so gulp.task('apply-prod-environment', function() { return process.env.NODE_ENV = 'production