redux

redux-observable dispatch actions

送分小仙女□ 提交于 2020-01-06 06:44:28
问题 I need to dispatch some actions in some order using redux-observable however, it takes just last action to dispatch. Please see example: export const fetchClientsEpic = (action$, { dispatch }) => action$ .ofType(fetchClients) .mapTo(fetchClientsPending(true)) .mergeMap(() => { return ajax .getJSON('some/get/clients/api') .map((clients: IClient[]) => { return fetchClientsSuccess( map(clients, (client, index) => ({ key: index, ...client, })), ); }); }); fetchClientsSuccess is dispatched with

writing the unit test case for the container in the react js

不羁的心 提交于 2020-01-06 06:08:56
问题 I am writing the unit test cases for the react containers, which are using the connect function. import React, { Component } from 'react'; import '../css/header.css'; import SignInInstruction from '../components/SingInInstruction'; import { connect } from 'react-redux'; import { fetchUserJd } from '../actions/index'; import NavBar from '../components/NavBar'; import { logoutUser } from '../../login/actions/index'; import { withRouter } from 'react-router-dom'; import { matchPath } from "react

React-Redux. Listen to store changes

社会主义新天地 提交于 2020-01-06 05:51:05
问题 How to trace changes in store from this component. In the external component Menu , I select the menu item and dispatch to store as parameter content . Depending on what I chose, I need to substitute the contents of the following component: class WorkSpace extends Component { constructor(props) { super(props); this.state = { content: this.props.mainStore.content } } render() { return ( <div className = "workspace"> //some content </div> ); } } export default connect( state => ({ mainStore:

I am getting Cannot read property 'then' of undefined while calling the api in react

限于喜欢 提交于 2020-01-06 05:43:10
问题 I am getting TypeError: Cannot read property 'then' of undefined when calling the api in react.js and redux. my component did mount function is - componentDidMount() { window.scrollTo(0, 0); var requestedId = this.props.match.params.id; this.props.fetchCategoryJoblist(requestedId).then(() => { this.setState({ loading: false }); }); } I am getting can not read property of then at this line this.props.fetchCategoryJoblist(requestedId).then(()) My componentDidMount function - componentDidMount()

Component not receiving new props

主宰稳场 提交于 2020-01-06 05:38:07
问题 I'm using react with redux and I'm having problems with a component connected to a list from a store. I have a list that whenever I click it adds an object or deletes it from the list with the action select, and I have a component connected to the state getting the list and rendering differently if the list is empty, length == 1 or >= 1. The list starts empty and when I add the first object the action is carried and the component re-renders, if I trigger the action again the component never

Testing custom hook: Invariant Violation: could not find react-redux context value; please ensure the component is wrapped in a <Provider>

回眸只為那壹抹淺笑 提交于 2020-01-06 05:36:12
问题 I got a custom hook which I want to test. It receives a redux store dispatch function and returns a function. In order to get the result I'm trying to do: const { result } = renderHook(() => { useSaveAuthenticationDataToStorages(useDispatch())}); However, I get an error: Invariant Violation: could not find react-redux context value; please ensure the component is wrapped in a It happens because of the useDispatch and that there is no store connected. However, I don't have any component here

Updating Store Before Custom Route

谁都会走 提交于 2020-01-06 05:30:08
问题 I am designing react application with node server. I have created a custom Private Route import React from 'react'; import {connect} from 'react-redux'; import {Route, Redirect} from 'react-router-dom'; class PrivateRoute extends React.Component{ render() { const { isAuthenticated, component: Component, ...rest } = this.props; return ( <Route {...rest} component={(props) => { if(isAuthenticated){ return <Component {...props}/> } else{ return <Redirect to="/login" /> } }}/> ) } } const

get particular job details based on jobId in redux and router

喜你入骨 提交于 2020-01-06 04:34:26
问题 i have list of jobs for different job id. i have to fetch the particular job details based on job id. I have created action and reducer function for that. But, i am new to redux not able to understand how to connect this with component and display the result. i am calling the api by axios to get the job details on particular id. I am not aware of how to make the call into the component. Now, I am getting undefined jobId. action.js export const retrieveLocations = (jobId) => (dispatch) => {

undefined this.props.children when getting async component with react router and webpack

橙三吉。 提交于 2020-01-06 03:51:05
问题 I'm using react, redux and react router among others to build and example app. I'm trying to load asynchronously different parts of my application. I've divided my app in ducks and I'm following this example https://github.com/insin/react-examples/tree/master/code-splitting-redux-reducers I'm using: react-router 2.0.1 webpack 1.12.13 webpack-dev-middleware 1.5.1 webpack-hot-middleware 2.6.4 My routes: import App from './components/layouts/app' import Home from './components/common/home'

Testing Redux Thunk Action Creator

左心房为你撑大大i 提交于 2020-01-06 02:53:07
问题 I've got a redux action creator that utilizes redux-thunk to do some logic to determine what to dispatch to the store. Its not promise-based, like an HTTP request would be, so I am having some issues with how to test it properly. Ill need a test for when the value meets the condition and for when it doesn't. Since the action creator does not return a promise, I cannot run a .then() in my test. What is the best way to test something like this? Likewise, I believe it would be pretty