From af7d1bbc63350610f3e37403795b2622b164d985 Mon Sep 17 00:00:00 2001 From: Nathan Hannig <8210763+nathanhannig@users.noreply.github.com> Date: Sun, 21 Oct 2018 10:30:12 -0700 Subject: [PATCH] fix: move component to components, duplicate articles (#23862) --- guide/english/react/component/index.md | 83 ------------------------- guide/english/react/components/index.md | 83 +++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 87 deletions(-) delete mode 100644 guide/english/react/component/index.md diff --git a/guide/english/react/component/index.md b/guide/english/react/component/index.md deleted file mode 100644 index fd58a3517c..0000000000 --- a/guide/english/react/component/index.md +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: React - Components ---- -## React - Components - -Components are reusable in react.js. You can inject value into props as given below : - -```jsx - -function Welcome(props) { - return

Hello, {props.name}

; -} - -const element = ; -ReactDOM.render( - element, - document.getElementById('root') -); - -``` - -The value ```name="Faisal Arkan"``` will be assigned to ```{props.name}``` from ```function Welcome(props)``` and returns a component ```

Hello, Faisal Arkan

``` which is saved into the const variable ```element```. The component can then be rendered via ```ReactDOM.render(element, document.getElementById('root'));```. ```document.getElementById('root')``` in this case is the target location you would like the ```element``` component to be rendered. - -### Other ways to declare components - -There are many ways to declare components when using React.js, but there are two kinds of components, ***stateless*** components and ***stateful*** components. - -### Stateful - -#### Class Type Components - -```jsx - -class Cat extends React.Component { - constructor(props) { - super(props); - - this.state = { - humor: 'happy' - } - } - render() { - return( -
-

{this.props.name}

-

- {this.props.color} -

-
- ); - } -} - -``` - -### Stateless Components - -#### Functional Components (Arrow Function from ES6) - -```jsx - -const Cat = props => { - return ( -
-

{props.name}

-

{props.color}

-
; - ); -}; - -``` - -#### Implicit Return Components - -```jsx - -const Cat = props => -
-

{props.name}

-

{props.color}

-
; - -``` diff --git a/guide/english/react/components/index.md b/guide/english/react/components/index.md index 4fd10565f0..b3f9bc476f 100644 --- a/guide/english/react/components/index.md +++ b/guide/english/react/components/index.md @@ -1,12 +1,87 @@ --- title: Components --- +## Components -# Components +Components are reusable in react.js. You can inject value into props as given below : -Components are the building blocks of React. +```jsx + +function Welcome(props) { + return

Hello, {props.name}

; +} + +const element = ; +ReactDOM.render( + element, + document.getElementById('root') +); + +``` + +The value ```name="Faisal Arkan"``` will be assigned to ```{props.name}``` from ```function Welcome(props)``` and returns a component ```

Hello, Faisal Arkan

``` which is saved into the const variable ```element```. The component can then be rendered via ```ReactDOM.render(element, document.getElementById('root'));```. ```document.getElementById('root')``` in this case is the target location you would like the ```element``` component to be rendered. + +### Other ways to declare components + +There are many ways to declare components when using React.js, but there are two kinds of components, ***stateless*** components and ***stateful*** components. + +### Stateful + +#### Class Type Components + +```jsx + +class Cat extends React.Component { + constructor(props) { + super(props); + + this.state = { + humor: 'happy' + } + } + render() { + return( +
+

{this.props.name}

+

+ {this.props.color} +

+
+ ); + } +} + +``` + +### Stateless Components + +#### Functional Components (Arrow Function from ES6) + +```jsx + +const Cat = props => { + return ( +
+

{props.name}

+

{props.color}

+
; + ); +}; + +``` + +#### Implicit Return Components + +```jsx + +const Cat = props => +
+

{props.name}

+

{props.color}

+
; + +``` ### More Information: -Components and Props -
+[https://reactjs.org/docs/components-and-props.html](Components and Props) \ No newline at end of file