reactjs - Please explain this abbreviated ES6 JSX declaration -


an example in survivejs handbook in chapter on react , webpack has me confused.

in note.jsx:

import react 'react';  export default () => <div>learn webpack</div>; 

this deviates in number of ways appears standard way of declaring react components using jsx:

import react 'react'; class note extends react.component {   render() {     return <div>learn webpack</div>;   } } 

how first example work?

  1. how know component called note can referred <note/> in parent component? filename match (removing .jsx part?)
  2. where's render() function? , how possible omit it?
  3. what limitations of approach? guessing works wrapping simple rendered output, mapping properties html...
  4. where style documented? can't seem find official documentation

  1. it doesn't, when <note /> looking variable named note in local scope. when component imported file, can name whatever want. e.g. import note './note'; import default-exported function in example.

  2. this stateless function component, https://facebook.github.io/react/docs/reusable-components.html#stateless-functions, linked yourself. function render, has no class instance.

  3. they can store no state since take inputs , render outputs.

  4. your specific example arrow function. documentation linked above uses standard non-arrow functions, interchangable in case. e.g.

    export default () => <div>learn webpack</div>; 

    is same as

    export default function(){   return <div>learn webpack</div>; } 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -