Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
Why my state argument when creating my Redux-Reducer is not being updated?

Help, My first time linking Redux to React.

My state argument has been passed with value but when in the switch statement the values assigned to the state is not read at return as the original value hello but the values from the return statement after it the No value becomes the initial then ADD.

when the page loads it shows state has the value of hello, but when I send an action the value of state changes to 'No'

This is my code

const MessageReducer = (state = "hello", action) => {
alert(state);
  switch (action.type) {
    case "ADD":
      // state.;
      alert(state);
      return "ADD";
    default:
      return "No";
  }
};
export default MessageReducer;

this is my configure store:

import MessageReducer from "../reducers/messageReducer";

export const store = configureStore({
  reducer: { preview: MessageReducer },
});

my makdown.js:

import React from "react";
import { connect } from "react-redux";
import MsgCreator from "../actions/msgAction";

class Markdown extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      current: "",
    };
    this.handleChange = this.handleChange.bind(this);
  }
  handleChange(event) {
    this.setState({
      current: event.target.value,
    });
    this.props.input(this.state.current);
  }
  render() {
    let i = this.props.messages;
    return (
      <div>
        <form>
          <label for="editor">Enter your text here: </label>
          <textarea
            id="editor"
            name="editor"
            value={this.props.current}
            onChange={this.handleChange}
          ></textarea>
        </form>
        <p id="preview">{i}</p>
      </div>
    );
  }
}

const mapStateToProps = (state) => {
  return {
    messages: state.preview,
  };
};

const mapDispatchToProps = (dispatch) => {
  return {
    input: (input) => {
      dispatch(MsgCreator(input));
    },
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(Markdown);

My App.js:

import React from "react";
import Markdown from "./components/markdown";
import "./App.css";

function App(props) {
  return (
    <div className="App">
      <h1>hello world</h1>
      <Markdown />
    </div>
  );
}

export default App;

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I didn’t see yow Provider={store} anywhere

<Provider store={store}>
<App/>
</Provider>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!