redux

Redux + React-router component not rendering

最后都变了- 提交于 2019-12-24 00:55:36
问题 So I'm trying to configure React-router with Redux I've used this example to setup a basic app. When I try to render my components I get 1 error and 2 warnings. The error is: Uncaught TypeError: Cannot read property 'toUpperCase' of undefined . Warning #1: Warning: React.createElement: type should not be null or undefined. It should be a string (for DOM elements) or a ReactClass (for composite components). Warning #2: Warning: Only functions or strings can be mounted as React components. I

How can I rerender a React component on path change?

人走茶凉 提交于 2019-12-24 00:46:24
问题 import React, { Component } from "react"; import PostContainer from "../../components/PostContainer"; import { connect } from "react-redux"; import { withRouter } from "react-router"; import API from "../../utils/API"; class User extends Component { constructor(props) { super(props); this.state = { posts: [], user: [] }; } componentDidMount() { API.findUserById(this.props.match.params.id) .then(res => { console.log(res); this.setState({ user: res.data }); }) .catch(err => console.log(err)); }

How to write test cases using jest and enzyme for connected components to my redux store?

点点圈 提交于 2019-12-24 00:29:27
问题 I want to write the test cases using jest, enzyme for my react component which connected with the redux store. The test case simply checks whether there is any "div" tag in the component or not. I have created a class component and connected it to the redux store. I have tried writing a simple test case which should log the html of the component using wrapper.debug(). //Category component import React, { Component } from 'react'; import { connect } from "react-redux"; import { Link } from

Get string result from function React Native

一笑奈何 提交于 2019-12-24 00:28:42
问题 I have created a component that connects to redux and returns the currently loaded item's name as the navigation title. But when I try to get the title from this component it breaks with this error: Error: `title` cannot be defined as a function in navigation options for `StockScreen` screen. Try replacing the following: { title: ({ state }) => state... } with: ({ navigation }) => ({ title: navigation.state... }) This is my component: import { connect } from 'react-redux'; let Title = () => {

Change state's array without changing the whole state (REACT / REDUX)

空扰寡人 提交于 2019-12-24 00:25:05
问题 I got a list of things to buy (for a little game i'm making with React) who is an array. It's in a state called "Market". And i have the other one, where i want to randomise all the value and stock them in another state. This is my Market list: let marketList = [ {"name": 'product name', "qty": 0, "minPrice": 10, "maxPrice": 100, "currentPrice": 0, "historyPrice": [], "historyQty": [], "available": false}, {"name": 'product name', "qty": 0, "minPrice": 30, "maxPrice": 200, "currentPrice": 0,

Spreading Redux Actions does not work in mapDispatchToProps

▼魔方 西西 提交于 2019-12-24 00:13:55
问题 My mapDispatchToProps works like this: const mapDispatchToProps = dispatch => ({ getCourts: () => dispatch(courtActions.getCourts()), selectStyle: style => dispatch(courtActions.selectStyle(style)), selectPoint: index => dispatch(courtActions.selectPoint(index)), sortPoints: sort => dispatch(courtActions.sortPoints(sort)) }); I want to write it like: const mapDispatchToProps = dispatch => ({ ...courtActions, }); but when I do that none of my actions work (they dont get dispatched). I'm sure

How to access state from inside mapDispatchToProps

。_饼干妹妹 提交于 2019-12-24 00:12:39
问题 Need to dispatch an action based on state or presentaional component's props. const mapDispatchToProps = (dispatch) => { return { onClick: () => { if (state.someValue || this.props.someValue){ dispatch({type: DO_SOMETHING}) } } } } and this action is supposed to be intercepted by redux-saga to do some remote fetching tasks, so I can't move this condition into reducer like: const reducer = (state, action) => { switch (action.type){ case DO_SOMETHING: if(state.someValue){ return {...state, //do

use react-redux with connect() and {…this.props}

喜你入骨 提交于 2019-12-23 23:21:02
问题 I cannot figure out, how to make right solution, when I want to call action in my container from other component, by the way I want to use spread operator because I need to pass too many parametrs in my component and don't want describe all of them. I know I can pass all props from redux store via props, like this example in Menu, but my component too nested, and I have to send props in eighter component in nest render() { return ( <div className="wrapper"> <Menu {...this.props} /> </div> );

Immutable.js deleteIn not working

雨燕双飞 提交于 2019-12-23 21:21:25
问题 I have been trying to solve this problem, but there is probably something of Immutable.js that I don't catch. I hope somebody can help me to understand. I have a test like this: import {List, Map} from 'immutable'; import {expect} from 'chai'; import {setInitial, addAtListOfMembers, removeAtListOfMembers } from '../src/core'; describe('removeAtListOfMembers', () => { it('remove a member to the list of members', () => { const state = Map({ removing: 3, infos : Map(), members: Map({ 1:Map({

REACT Uncaught TypeError .then is not a function

夙愿已清 提交于 2019-12-23 19:23:08
问题 i'm doing function in my react component like this : const Logged = (props) => { const doLogout = () => { props.logout().then(() => browserHistory.push('/')); } return( <IconMenu {...Props} iconButtonElement={ <IconButton><MoreVertIcon /></IconButton> } targetOrigin={{horizontal: 'right', vertical: 'top'}} anchorOrigin={{horizontal: 'right', vertical: 'top'}} > <MenuItem primaryText="Sign out" onTouchTap={doLogout} /> </IconMenu> ) }; i already wrap the dispatch in the component and connect