JavaScript Destructuring props in pure function components

Suppose we have the following pure function:

const HeaderComponent = () => (
  <h1> Title <h1>
)

export default HeaderComponent

Now I need to receive the new title from props, so we often destructure this.props to avoid accessing title with this.props.title and in the render method we will have something like:

render() {
  const {Title} = this.props;
  return(
    <h1> {Title} </h1>
  )
}

The thing is we have to extend React.Component class to access render method.

Is it possible to use the destructure in pure functions?

const HeaderComponent = props => (
   // const {Title} = this.props;
) 
Answer:1

You can do it like this. I also find it a nice way of making the function self documenting.

const HeaderComponent = ({ title }) => (
   <h1>{ title }<h1>
)

Also can set default values

const HeaderComponent = ({ title: 'Default Title' }) => (
   <h1>{ title }<h1>
)

UPDATE: As T.J. Crowder points out, Title is capitalized in your examples above. In the text portion it is lowercase; as that is the norm, I have used the lowercase version

Answer:2

I got the following input Wed, 08 Feb 2017 10:09:19 GMT form server. I've been trying to parse this string with momentjs but couldn't find format that will parse the GMT right. and if i'm not ...

I got the following input Wed, 08 Feb 2017 10:09:19 GMT form server. I've been trying to parse this string with momentjs but couldn't find format that will parse the GMT right. and if i'm not ...

  1. parsing date string python
  2. parsing date string in javascript
  3. parsing date string in java 8
  4. parsing date string in java
  5. parsing date string js
  6. parsing date string in c#
  7. parsing date string format
  8. parsing string date
  9. error parsing date string
  10. error parsing date string jira
  11. perl parsing date string
  12. parsing date into string
  13. parsing date into string javascript
  14. jira api error parsing date string
  15. python parsing datetime string
  16. parsing java.util.date string

Consider this code :- function Rectangle(length, width) { this.length = length; this.width = width; } Rectangle.prototype.getArea = function() { return this.length * this.width; }; ...

Consider this code :- function Rectangle(length, width) { this.length = length; this.width = width; } Rectangle.prototype.getArea = function() { return this.length * this.width; }; ...

  1. sap authorization object create user
  2. create object based on user input java
  3. create a token object user right
  4. powerbuilder create user object
  5. create object from user input java
  6. django create user object
  7. grasshopper create user object
  8. create user defined object in javascript
  9. powershell create user object
  10. powerbuilder create user object dynamically
  11. create object from user input javascript
  12. create user defined object in vba
  13. create dm_user object
  14. create object based on user input c#
  15. javascript create user object
  16. c# create user object
  17. java create user object
  18. vba create user object
  19. create user object
  20. create object with user input

I am using https://github.com/fatlinesofcode/ngDraggable. <div ng-drag="true" ng-drop="true" ng-drag-start="example($data,$event)" > </div> The div is to be dropped right there where ...

I am using https://github.com/fatlinesofcode/ngDraggable. <div ng-drag="true" ng-drop="true" ng-drag-start="example($data,$event)" > </div> The div is to be dropped right there where ...

  1. allow drag div
  2. html5 allow drag element

I have an issue with the following code. I want to replace a string by another one, and generate an img code. However, I got an error message: str.replace is not a function. Any idea why? <...

I have an issue with the following code. I want to replace a string by another one, and generate an img code. However, I got an error message: str.replace is not a function. Any idea why? <...

  1. javascript replace function arguments
  2. javascript replace function not working
  3. javascript replace function string
  4. javascript replace function body
  5. javascript replace function with regex
  6. javascript replace function implementation
  7. javascript replace function with regular expression
  8. javascript replace function
  9. javascript replace function example
  10. javascript replace function parameter
  11. javascript replace function callback
  12. javascript replace function for special characters
  13. javascript replace function in object
  14. javascript replace function prototype
  15. javascript replace function not working in ie
  16. javascript replace function w3schools
  17. javascript replace function escape characters
  18. javascript replace function return value
  19. javascript replace function multiple
  20. javascript replace function browser compatibility