Posts

Showing posts with the label redux

combinereducers initial state error

Image
Clash Royale CLAN TAG #URR8PPP combinereducers initial state error So I just had one redux reducer in my app called rootreducer.js but renamed it into a reducer called pics and added it to an index file with combineReducers. export default function rootReducer(state = { images: , filtered: , isFetching: false }, action) { let imagepics = Object.assign(, state.imagepics) switch (action.type) { case "INVALIDATE_IMAGE": return { ...state, didInvalidate: true } case "REQUEST_IMAGES": return { ...state, isFetching: true } case "SEARCH_IMAGES": let filtered = action.payload return {...state, images: action.payload, filtered, isFetching: false} default: return state } } I structured my pics reducers just like the previous one, however empty arrays for images and filtered in the new pics reducer is causing my app not to load. How do I set the intial state for...

Im am getting undefined with mapstatetoprops

Image
Clash Royale CLAN TAG #URR8PPP Im am getting undefined with mapstatetoprops I am trying pass logged data from my redux actions to the front end but keep getting user.name of null or undefined. This is the front end where I am simply trying to get user.name to appear so that it says Hi user.name(name of persons account). import React, { Component } from "react"; import { NewPropertyForm, FormPageOne, FormPageTwo, FormPageThree, FormPageFour } from "../../components/NewPropertyForm"; import { PropertyList } from "../../components/PropertyList"; import { Container, Button, Modal, ModalCard, ModalCardTitle, ModalBackground, ModalCardFooter, ModalCardHeader, Delete, ModalCardBody } from 'bloomer'; import StepZilla from "react-stepzilla"; import modal from "./modal-bg.svg"; import "./Manager.css"; import {login} from '../../actions/authActions' import {connect} from 'react-redux'; import { bindActionCr...

object can't get method or property 'getCars'

Image
Clash Royale CLAN TAG #URR8PPP object can't get method or property 'getCars' i'm working on react-redux intermidiate..but i don't know what's going wrong on this project hera i have creacted the searchbar for getting car details..and the file is created as 'search.js'...you can see here.. search.js import React, { Component } from 'react'; import { connect } from 'react-redux'; import { getCars } from '../actions'; import { bindActionCreators } from 'redux'; class Search extends Component{ constructor(props){ super(props); this.state = { keyword:'' } } searchCars = (event) => { event.preventDefault(); this.props.getCars(this.state.keyword) } handleChange = (event) => { this.setState({ keyword:event.target.value }) } componentDidMount(){ console.log...

Why data is not rendering into template for react and redux?

Image
Clash Royale CLAN TAG #URR8PPP Why data is not rendering into template for react and redux? I am new to ReactJS: My code is : class HomePage extends React.Component { render() { const { users } = this.props; console.log(this.props.users.items);//Line 1 console.log(this.props.users.items.name);//Line 2 return ( <div className="col-md-6 col-md-offset-3"> <h1>Hi {users.name}!</h1><!--Line 3--> </div> ); } } function mapStateToProps(state) { const { users } = state; return { users }; } For Reducer code: export function users(state = {}, action) { switch (action.type) { case 'SUCCESS': return { items: action.users }; default: return state } } For LINE 1 its showing data in console but when i try to fetch specific property as in LINE 2 from object it generate an error and also rendering data into te...

React/Redux how to access the state in the networkservice

Image
Clash Royale CLAN TAG #URR8PPP React/Redux how to access the state in the networkservice I have created a Network service component which deals with the API call. I want to retrieve state from other components which update the store . Im having trouble getting the state so I started using Redux, but I havent used Redux before and still trying to find a way to pass the state to the NetworkService . Any help would be great, thanks! store NetworkService Here is my NetworkService.js import RequestService from './RequestService'; import store from '../store'; const BASE_URL = 'api.example.com/'; const REGION_ID = //Trying to find a way to get the state here // My attempt to get the state, but this unsubscribes and // doesnt return the value as it is async let Updated = store.subscribe(() => { let REGION_ID = store.getState().regionId; }) class NetworkService { getForecast48Regional(){ let url =`${BASE_URL}/${REGION_ID }`; return RequestServi...

Defined function is undefined when called React-Native [on hold]

Image
Defined function is undefined when called React-Native [on hold] I'm currently working on an application in React-Native implementing Redux and Thunk and I stumbled across an error I can't figure out: My view container ( The one that connect the component view with a mapStateTopProps and a mapDispatchToProps ) set a method named 'getAllEvents()' in my component props. Even if the method is defined as shown on the screenshot below, I get an undefined whenever I call it... this.props.getAllEvents => [Function getAllEvents] this.props.getAllEvents() => undefined How can a defined function could return undefined when it is called? This question appears to be off-topic. The users who voted to close gave this specific reason: stackoverflow.com/help/how-to-ask – Zyigh 22 mins ago thanks, I've e...