-1

I want code, to track live location using react.js so I have gone through this below provide link and I just want to know why props is used instead of state in state full component ?

https://www.npmjs.com/package/react-geolocated

Can someone help me why they used props?

Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231
Fayaz
  • 11
  • 4
  • Possible duplicate of [What is the difference between state and props in React?](https://stackoverflow.com/questions/27991366/what-is-the-difference-between-state-and-props-in-react) – Bhojendra Rauniyar Mar 22 '19 at 20:25
  • 1
    please fix your question – AlexZvl Mar 22 '19 at 20:28
  • Rauniyar !! props can be used in stateless components and state is used in state full components ..but here my query is why are they used props in state full components? – Fayaz Mar 22 '19 at 20:29

1 Answers1

1

You're on wrong track. Props can be used either in stateful component or stateless component.

By meaning stateful component is not just for maintaining states. Nor stateless component just for maintaining props.

stateful !== states
stateless !== props

You can take this for short:

stateful <=> states <=> props
stateless <=> props <=> states

Where you can see (in short, there's more... look at the references), stateful component passes the states/props, the child component can use props, stateless component links props and hooks the states. - You might feel difficulty reading this line of statement.

Come back later after following the references to understand what I wanted to say, you'll obviously know what I meant for.

If you want to look about the differences between props vs state, then look at attached duplicate post:

What is the difference between state and props in React?

I would also suggest you to look at the docs about lifting state up.

Here's the link to the docs for props and states:

Components and props

State and lifecycle

By reading these references, you should have clear understanding of props and states.

Bhojendra Rauniyar
  • 83,432
  • 35
  • 168
  • 231