Reputation: 2343
the es6 syntax for creating React component is export default class ExampleComponent extends React.Component
.However it still work when export default class ExampleComponent
without extends React.Component
on condition that import React from 'react'
; why this happen
Upvotes: 5
Views: 3772
Reputation: 4441
It's easy to be in this situation and miss what's happening, but the difference is really huge: without extending React.Component, you're just creating a JS class. Furthermore:
React.createClass()
or as an ES6 class), it'll still "work", state
for everythingHope that helps!
Upvotes: 5
Reputation: 1432
You are creating a "pure" JavaScript class, but once it is not extending a React.Component
you will be unable to access specific React behavior. Check how extends work.
Upvotes: 2