redux

React/Redux download file

吃可爱长大的小学妹 提交于 2019-12-19 05:04:12
问题 I need to download a file from the server when a button is clicked. I created a MaterialUI button and on its onclick callback i call an action of the container component connected . The action is asynchronous and does an ajax POST: export const onXlsxClick = () => dispatch => { const urlParams = { filters: { aggregation: 'macro_area', chart_resolution: '1_hour', chart_from: '1478080363', chart_to: '1477993963' }, labels: ['PROVA1', 'PROVA2'], series: [ { label: null, timestamp: 1478080363,

Validate dynamically generated form in react using redux-form and revalidate?

百般思念 提交于 2019-12-19 02:40:47
问题 I'm using "revalidate" to validate "redux-form" forms, but I'm facing this situation where there's a form that is generated dynamically based on an API response that I map over it and display the inputs inside the form. Here's an example of how I normally validate "redux forms" with "revalidate ... const validate = combineValidators({ name: composeValidators( isRequired({ message: "Please enter your full name." }), hasLengthLessThan(255)({ message: "Name can't exceed 255 characters." }) )(),

Redux: Using async middlewares vs dispatching actions on success functions

人盡茶涼 提交于 2019-12-18 17:25:27
问题 I am trying to integrate Redux into my React project. Currently I'm not using any Flux framework. My app gets some data from the API and displays it in a pretty way, like so: componentDidMount() { getData(); } getData() { const self = this; ajax({ url: apiUrl, }) .success(function(data) { self.setState({ data: data, }); }) .error(function() { throw new Error('Server response failed.'); }); } In reading about Redux, I've settled on two possible approaches that I could use for handling storing

What is a Payload in Redux context

孤街醉人 提交于 2019-12-18 15:46:49
问题 Can someone please explain what exactly a Payload is in Redux context? In layman terms please, the technical term wasn't useful. Hence still the confusion. What I understand is that Payload is the actual data that is transmitted over the network. Does this mean, Payload of an action in Redux context means that the data that is passed as a parameter while an action is emitted to change the Redux state ? 回答1: tl;dr Payload is a non-official, community accepted (de facto) naming convention for

Adding Redux to an existing React app

只愿长相守 提交于 2019-12-18 13:15:57
问题 I've been working on a React app and have gotten to a point where I'll need Redux to handle some aspects of it. After reading a bunch of tutorials, I'm fairly stuck on how to make my "smarter" components "dumber" and move functions into my actions and reducers. So, for example, one aspect of the app is more of a to-do list style. One of my classes starts like this: export default class ItemList extends React.Component { constructor() { super(); this.state = { items: [], completed: [], }; this

Dynamically load initialValues in Redux Form

天大地大妈咪最大 提交于 2019-12-18 13:13:31
问题 Using the example of initializingFromState within Redux-Form, I am trying to set this up dynamically. This is to edit a particular book in a list of books, and is using a simple api set up in express.js. The full container is below. I somehow need to pass in initialValues , within the mapStateToProps function. In the example, it is done via a static object, but I can't work out how to use the information I have pulled in via fetchBook , and pass it to initialValues . Container: import React,

Warning: Failed prop type: The prop `store` is marked as required in `Provider`, but its value is `undefined`. in Provider

断了今生、忘了曾经 提交于 2019-12-18 13:12:13
问题 How to resolve this error in react-redux project error screenshot Warning: Failed prop type: The prop store is marked as required in Provider , but its value is undefined . in Provider import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import './index.css'; import SignUp from './Components/SignUp' import SignIn from './Components/SignIn' import Home from './Components/Home' import { Router, Route, hashHistory, IndexRoute, browserHistory } from 'react-router'

Warning: Failed prop type: The prop `store` is marked as required in `Provider`, but its value is `undefined`. in Provider

送分小仙女□ 提交于 2019-12-18 13:11:15
问题 How to resolve this error in react-redux project error screenshot Warning: Failed prop type: The prop store is marked as required in Provider , but its value is undefined . in Provider import React from 'react'; import ReactDOM from 'react-dom'; import App from './App'; import './index.css'; import SignUp from './Components/SignUp' import SignIn from './Components/SignIn' import Home from './Components/Home' import { Router, Route, hashHistory, IndexRoute, browserHistory } from 'react-router'

React + Redux, How to render not after each dispatch, but after several?

倖福魔咒の 提交于 2019-12-18 12:58:23
问题 I am trying to make multiple changes to the store, but not render till all changes are done. I wanted to do this with redux-thunk. Here is my action creator: function addProp(name, value) { return { type:'ADD_PROP', name, value } } function multiGeoChanges(...changes) { // my goal here is to make multiple changes to geo, and make sure that react doesnt update the render till the end return async function(dispatch, getState) { for (let change of changes) { dispatch(change); await

What does “Stateless function components cannot be given refs” mean?

懵懂的女人 提交于 2019-12-18 12:45:05
问题 I have this: const ProjectsSummaryLayout = ({projects}) => { return ( <div className="projects-summary col-md-10"> <h3>Projects</h3> <ul> { projects.map(p => <li key={p.id}>{p.contract.client}</li>) } </ul> </div> ) } const ProjectsSummary = connect( state => ({projects: state.projects}) )(ProjectsSummaryLayout) and I get: Warning: Stateless function components cannot be given refs (See ref "wrappedInstance" in ProjectsSummaryLayout created by Connect(ProjectsSummaryLayout)). Attempts to