Try to search your question here, if you can't find : Ask Any Question Now ?

Why is reducer failing to update the store?

HomeCategory: stackoverflowWhy is reducer failing to update the store?
willson asked 2 weeks ago

It looks to me like I have my component, action creator, and reducer all set up correctly, but for some reason, my store isn’t being updated when I move the slider.

This is my App.js file sans imports

class App extends React.Component {
  state = {
    value: 100,
  };

  handleChange = (event, value) => {
    this.setState({ value });
    console.log(value)
    this.props.dispatch(PriceFilter(value))
  };

  render() {
    console.log(this.props)

    return (
      <div style={styles.root}>
        <Slider
          value={this.state.value}
          onChange={this.handleChange}
        />
      </div>
    );
  }
}

const mapStateToProps = (state) => {
  return { price: state.reducers }
}

export default connect(mapStateToProps)(App)

My action is super simple

export const PriceFilter = (price) => ({
    type: 'PRICE_FILTER',
    price: price
})

My reducer is also very basic:

const initialState = {
    price: 10000
}

const priceReducer = (state = initialState, action) => {
    switch(action.type) {
        case 'PRICE_FILTER':
            return {
                ...state,
                price: action.price
            }
        default:
            return state
    }
}

export default priceReducer

Does anyone know what I could be doing wrong?

1 Answers
Best Answer
Mannu answered 2 weeks ago
Your Answer

14 + 1 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com