Switchcase made for REACTFLUX is not getting the right case

Asked

Viewed 15 times

0

Why aren’t you getting the.type action? just exits by default.

The log is saying "editing" which is the default case instead of creating a new article.

The code

  handleActions(action) {
    switch (action) {
    case action.type === ActionTypes.CREATE_ARTICLE:
        this.setState.article.id = Counter.increment();
        this.setState.article.title = action.title;
        this.setState.article.content = action.content;
        console.log("adicionado")
        break;
    case action.type === ActionTypes.DELETE_ARTICLE:
        console.log("deletando")
        break;
    default:
        console.log("editando")
        break;
}
  }

Log print:

Here the log print

In the image above creates the object but the log leaves in the default "editing".

Whole code

  • What gives console.log(action, ActionTypes.CREATE_ARTICLE);?

  • Gives the screenshot of the print I posted on the question. This object of type CREATE_ARTICLE.

  • And console.log(ActionTypes.CREATE_ARTICLE);?

  • same thing. The bid is q instead of falling into case 1 which is the CREATE_ARTICLE is falling into the default. That’s the problem.

  • @Sergio I changed the code a little and the error changed. Now it appears this: TypeError: Cannot read property 'article' of undefined It is on that line:this.setState.article.id = Counter.increment(); And the constructor that has this id is this: ;constructor() {
 super();
 this.article = {
 id: "",
 title: "",
 article: ""
 }
 }

1 answer

0

Well it looks like Flux doesn’t have state and these Components stops. I talked to the official group of the team React and the best option for me is to do a gambiarra or go to Redux. I only have one thing to say:"Bye Flux!"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.