From ff14591fe3987a0cb7415a4f47a4f29b6eb4cb54 Mon Sep 17 00:00:00 2001 From: Ojini Chizoba Jude Date: Sat, 12 Jan 2019 17:12:30 +0100 Subject: [PATCH] grammatical adjustment on line 12 (#28189) --- guide/english/react/state-vs-props/index.md | 166 ++++++++++---------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/guide/english/react/state-vs-props/index.md b/guide/english/react/state-vs-props/index.md index a19a0cf917..2cff6b152b 100644 --- a/guide/english/react/state-vs-props/index.md +++ b/guide/english/react/state-vs-props/index.md @@ -1,83 +1,83 @@ ---- -title: State vs Props ---- -## State vs Props - -When we start working with React components, we frequently hear two terms. These are `state` and `props`. So, in this article we will explore what those are and how they differ. - -## State: - -* State is something that a component owns. It belongs to that particular component where it is defined. -For example, A person's age is a state of that person. -* State is mutable. But it can be changed by only by the component itself, meaning it is private. As I only can change my age, no one else can. -* You can change the state by using `this.setState()` - -See the below example to get an idea of state: - -#### Person.js - -```javascript - import React from 'react'; - - class Person extends React.Component{ - constructor(props) { - super(props); - this.state = { - age:0 - this.incrementAge = this.incrementAge.bind(this) - } - - incrementAge(){ - this.setState({ - age:this.state.age + 1; - }); - } - - render(){ - return( -
- - -
- ); - } - } - - export default Person; -``` -In the above example, `age` is the state of `Person` component. - -## Props: - -* Props are similar to method arguments. They are passed to a component when it is instantiated. -* Props are immutable. They are read-only. - -See the below example to get an idea of Props: - -#### Person.js - -```javascript - import React from 'react'; - - class Person extends React.Component{ - render(){ - return( -
- -
- ); - } - } - - export default Person; - - const person = -``` - -In the above example, `const person = ` we are passing `character = "good"` prop to `Person` component. - -It gives output as "I am a good person", in fact I am. - -There is lot more to learn on State and Props. Many things can be learnt by actually diving into coding. So get your hands dirty by coding. - -Happy Coding !!! +--- +title: State vs Props +--- +## State vs Props + +When we start working with React components, we frequently hear two terms. These are `state` and `props`. So, in this article we will explore what those are and how they differ. + +## State: + +* State is something that a component owns. It belongs to that particular component where it is defined. +For example, A person's age is a state of that person. +* State is mutable. But it can only be changed by the component itself, meaning it is private. As I only can change my age, no one else can. +* You can change the state by using `this.setState()` + +See the below example to get an idea of state: + +#### Person.js + +```javascript + import React from 'react'; + + class Person extends React.Component{ + constructor(props) { + super(props); + this.state = { + age:0 + this.incrementAge = this.incrementAge.bind(this) + } + + incrementAge(){ + this.setState({ + age:this.state.age + 1; + }); + } + + render(){ + return( +
+ + +
+ ); + } + } + + export default Person; +``` +In the above example, `age` is the state of `Person` component. + +## Props: + +* Props are similar to method arguments. They are passed to a component when it is instantiated. +* Props are immutable. They are read-only. + +See the below example to get an idea of Props: + +#### Person.js + +```javascript + import React from 'react'; + + class Person extends React.Component{ + render(){ + return( +
+ +
+ ); + } + } + + export default Person; + + const person = +``` + +In the above example, `const person = ` we are passing `character = "good"` prop to `Person` component. + +It gives output as "I am a good person", in fact I am. + +There is lot more to learn on State and Props. Many things can be learnt by actually diving into coding. So get your hands dirty by coding. + +Happy Coding !!!