Do not redistribute React.Component

es6 syntax for creating a React component is equal export default class ExampleComponent extends React.Component. However, it still works when export default class ExampleComponentwithout extends React.Component, provided that import React from 'react'; Why is this happening

+4
source share
2 answers

It's easy to be in this situation and skip what happens, but the difference is really huge: without the React.Component extension, you simply create a JS class. Besides:

  • because it satisfies the requirements of the React class (which can be created using React.createClass()or as an ES6 class), it "works" anyway,
  • , lifeCyle (- , , , bc, ).
  • " " , , , "" "", () , - .
  • , , , , "" . ; state

, !

+3

"" JavaScript, React.Component, . .

0

All Articles