0

I am learning React and JavaScript.

I have this Redux Store that looks like this very simple:

const initialState = {
  booksList: [],
  progress: false,
  faild: "",
  log: ""
};

When I do mapStateToProps to my Component then I don't get a log='' but I get something else. Basically what I try to do is this if(log != "") as the image show but I get a true when I want to get a false because initial Store is empty.

As the image show the log also contains a function the Redux store dispatch.

enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
Kid
  • 1,869
  • 3
  • 19
  • 48
  • Hi, having the full code will help us to visualize why your condition is true instead of false, thanks. By the way, you should be using this.props.log right ? – Ko2r Apr 09 '21 at 11:26
  • There is no "this" I dont use Rect.Component – Kid Apr 09 '21 at 11:35

2 Answers2

2

Currently the log parameter corresponds to your component properties (containing two properties log and dispatch)

You must declare your component like this :

function Logger({log}) {
  ...
} 

or like this

function Logger(props) {
  const log = props.log;
  ...
} 
Olivier Boissé
  • 15,834
  • 6
  • 38
  • 56
1

In JavaScript, undefined == "" returns true.

You want to use the operators === and !== instead of == and !=.

phry
  • 35,762
  • 5
  • 67
  • 81