score:2
you need to pass props in super only if you want to access this.props in constructor of the class.
class base extends react.component {
constructor(props) {
console.log('base', props);
}
render() {
return <div>base {this.props.name}</div>;
}
}
class sub extends base {
constructor(props) {
super({
name: 'new name prop'
});
console.log('sub', arguments);
}
}
var sub = <sub name="gomic" />
react.render(sub, document.getelementbyid('container'));
props are by default not assigned in the constructor. they are assinged in the method react.createelement. so super(props)
should be called only when the superclass's constructor manually assings props
to this.props
. when you just extend the react.component
calling super(props)
method will do nothing with props
.
reference:
Source: stackoverflow.com
Related Query
- When making react components es6 syntax why is super initialised with props?
- React props syntax with ES6 spread operator
- Making a SVG React Material-UI icon in an NPM module with ES6 syntax
- When to use ES6 class based React components vs. functional ES6 React components?
- How to connect state to props with mobx.js @observer when use ES6 class?
- React memo components and re-render when passing function as props
- React w/ TypeScript: why is the type for the state lost when useState with a callback as the updater
- Why does react hook throw the act error when used with fetch api?
- HOC's and Render Props With Functional Components in React 16
- I can't understand why components with 'connect()' are stateful in react
- Making full-size main content with semantic-UI Sidebar react components
- Why is it necessary to use bind when working with ES6 and ReactJS?
- WebStorm inspector throws warning when setting initial React state with ES6
- How to optimize React components with React.memo and useCallback when callbacks are changing state in the parent
- Why do my styled component keyframes error with ts-styled-plugin(9999) in react when using percentage instead of TO/FROM
- Why is React component rerendering when props has not changed?
- svg not rendering correctly when used with by multiple react components
- How to use inheritance with React components and es6 classes
- Why do I need to do export const useAppDispatch = () => useDispatch<AppDispatch>() when using Typescript with React
- React - Draggable components with inputs lose the ability to focus when clicking that input
- How to mock Publish/subscribe events on React Components when using PubSubJS with Jest/Enzyme?
- Why credit card autofill doesn't work when production build but it works with npm start in my react application?
- Spreading Props TypeScript with React and Styled Components
- I want rerender when props data change with react hooks but i got infinite rerender
- Why are we requiring React and ReactDOM as modules when working with Webpack? It takes long to produce output
- Why react rerendres components even if props didn't changed?
- Why child component didnt get parent's props with Axios in React
- React components not rendering when routing to new page with react-router-dom v6
- Reading data from Firebase 3 into a React component with ES6 syntax
- React - functional components keep re-render when passing functions as props
More Query from same tag
- How do I render specific results using Giphy API?
- Ionic Reactjs Parsing error: Expression expected when rendering element based on Select Box
- react js cannot get updated value in setState callback function
- Firebase .once() in React Firebase useList hook
- My call async/await returns a Promise {<pending>} in my actions
- Refactoring from js to tsx
- Table generates twice while only being called once
- Solve pagination issues
- Is it possible to use Sass variable within styled-component @media query?
- In react what does (obj: any) => boolean do?
- How to remove UI components using React JS
- Value null is converted into "" with React on input types
- How to get the current full URL in Next.js/Typescript component?
- How can I set state from data in array by using useState?
- Syntax Error React.js
- I can render my page just once. After refreshing the page, i am getting an error as cant find data from api. Please let me know my mistake
- history push is pushing two times same key
- React component with dynamic h1, h2, h3 etc tags
- Testing redux-saga functions that have api calls
- Uncaught Invariant Violation using React Bootstrap modal
- Update antd form if initialValue is changed
- I am getting an error when using class components in Gatsby
- react-dates solution to select single date from calendar
- React Error Boundaries not working with React
- How to send props by clicking image in React
- Extract values from list of dictionaries and populate component
- N.map is not a function
- React: Return Statement
- Passing data from a single JSON file from parent to child component in React using dynamic routes
- Can anyone help me replace this Segment with a Modal in ReactJS