redux

How to access current location in reducer (redux-router)?

五迷三道 提交于 2019-12-23 09:18:01
问题 How would i get the current path and query of the current location with redux-router in reducer. I am able to get the pathname easily inside the component with mapStateToProps, but i want to access the current path in reducer. I am using redux-router 1.0.0-beta7, react-router 1.0.3. 回答1: 1 .way - pass pathname with particular action through redux-thunk and getState() const someAction = data =>(dispatch,getState)=>{ dispatch({ type:'SOME_ACTION', pathname:getState().router.pathname }) } 2 .way

Incrementing Click Redux Function in an array

喜夏-厌秋 提交于 2019-12-23 07:07:46
问题 I am working with some svg elements and i have built an increment button. The increment button takes the the path d values converts it into an array and sums 5 from the third element of the array. If the element is 'L' or 'M' it does nothing Here the click function in the redux, it takes the values of the incrementing action state const a = action.index; let string = state[a].d; It converts in an array let array = string.split(" "); and then it does all the calculation i said in the loop See

Async initial state React-Redux Redux-Thunk

廉价感情. 提交于 2019-12-23 07:03:23
问题 Using React , Redux , Redux-thunk I want to have an initial state through a server request (API call) but I cannot seem to get this to work. What I have got so far: var Redux = require('redux'); var carReducer = require('./reducers/cars'); var thunk = require('redux-thunk').default; var initialState = require('./reducers/initialState'); var rootReducer = Redux.combineReducers({ cars: carReducer }); module.exports = Redux.applyMiddleware(thunk)(Redux.createStore)(rootReducer, initialState

How to reset initial value in redux form

允我心安 提交于 2019-12-23 06:52:48
问题 I'm using redux-form. I'm showing initial values in input fields from the state. When I click on reset, the input field is still showing initial values. How can I reset the input field? This is my code : const mapStateToProps = (state) => { return { initialValues: { name:state.userInfo.data.name, email:state.userInfo.data.email, phone:state.userInfo.data.phone, city:state.userInfo.data.city.name, } }; } This is how I'm calling initial value in the input field. const renderField = ({ input,

How to reset initial value in redux form

感情迁移 提交于 2019-12-23 06:51:39
问题 I'm using redux-form. I'm showing initial values in input fields from the state. When I click on reset, the input field is still showing initial values. How can I reset the input field? This is my code : const mapStateToProps = (state) => { return { initialValues: { name:state.userInfo.data.name, email:state.userInfo.data.email, phone:state.userInfo.data.phone, city:state.userInfo.data.city.name, } }; } This is how I'm calling initial value in the input field. const renderField = ({ input,

How React rerenders tree, if both parent and child components are dependent from one Redux store prop?

自古美人都是妖i 提交于 2019-12-23 05:49:08
问题 I have Layout component, which checks if user is logged in. It simply examines user prop in Redux store. If it is, it renders children, otherwise Login . Layout.jsx const Layout = ({ user, children }) => { if (user) return children; return <Login />; }; export default connect(state => ({ user: state.user }))(Layout); Profile.jsx const Profile = ({ user }) => <div>{user.name}</div>; export default connect(state => ({ user: state.user }))(Profile); App itself <Layout> <Profile /> </Layout> The

How to set md-select panel to be open by default

蹲街弑〆低调 提交于 2019-12-23 05:17:27
问题 I am using angular4 with Redux and angular material to design my web page. I am trying to set the md-select panel to be open. example scenario: click button dispatches an action to open the select panel opens to dispaly all options. I am using redux actions to manipulate my components state. So basically I need to fire an action to set the select to open. Any suggestions? 回答1: Using the Material2 example as starting point for this answer. Here is how you can do that: Give an id to your panel,

How do i sort (swap) items inside an Immutable Map?

丶灬走出姿态 提交于 2019-12-23 05:15:37
问题 I want to swap items inside an immutable list within a Map , example: const Map = Immutable.fromJS({ name:'lolo', ids:[3,4,5] }); i am trying to use splice to do the swapping, also tried with insert() an Immutable method. Lets say i want to swap from [3, 4, 5] to [3, 5, 4] , i am truing something like this: list.set('ids', list.get('ids').splice(2, 0, list.get('ids').splice(1, 1)[0]) What's the best way to sort elements inside an Immutable data structures with Immutable.js ? 回答1: You should

How to do server side rendering with Redux + Immutable js?

我是研究僧i 提交于 2019-12-23 05:10:51
问题 I would like to Use Immutable js with my App .But It's Kinda difficult for server side rendering It throws me a error like this TypeError: state.allPosts.toJS is not a function Home.js import React,{Component} from 'react'; import {Helmet} from 'react-helmet'; import {connect} from 'react-redux'; import * as allPosts from '../Redux/Actions/AllPosts_action' class Home extends Component{ renderAllPosts(){ const {posts} = this.props; return( posts.postArr.map(({id,title,body}) => { return <li

How to chain async actions and wait for the result without store.dispatch

廉价感情. 提交于 2019-12-23 04:47:49
问题 I'm trying to write my INITIALIZE action which should chain some async actions together in the following way Call the initialize action. Call two async actions simultaneously. Wait for the completion of above actions. Run additional one action. Finish initialization. here is the redux flow that I expect INITIALIZATION_STARTED => ASYNC_ACTION_A_STARTED AND ASYNC_ACTION_B_STARTED => ASYNC_ACTION_A_FINISHED AND ASYNC_ACTION_B_FINISHED => ASYNC_ACTION_C_STARTED => ASYNC_ACTION_C_FINISHED =>