5

Why do I have 'props' passed as parameter in ReactJS and it doesn't happen when I use ReduxJS?

for example:

React app:

 constructor(props){
    super(props);
    this.state = {
      memeLimit: 10
    }
 }

Redux app:

constructor(){
    super();
    this.state = {
      memeLimit: 10
    }
 }

Thank you

claudiopb
  • 1,056
  • 1
  • 13
  • 25

1 Answers1

5

The reason to use super(props); is to be able to use this.props inside the constructor, otherwise you don't need super(props);

For example

 constructor(props){
    super(props);
    this.state = {
      memeLimit: this.props.memeLimit // Here you can use this.props
    }
 }

This is equivalent to

 constructor(props){
    super();
    this.state = {
      memeLimit: props.memeLimit // Here you cannot use this.props
    }
 }

This not really related to Redux Vs React

You can check this for more details: What's the difference between "super()" and "super(props)" in React when using es6 classes?

Anas
  • 5,622
  • 5
  • 39
  • 71