- The object
**getInitialState()**Invoked once before the component is mounted. The return value will be used as the initial value of this.state.
Note: This method is not available on ES6 class components that extend React.Component. For more information, please read our documentation about ES6 classes.
- The object
**getDefaultProps()**Invoked once and cached when the class is created. Values in the mapping will be set on this.props if that prop is not specified by the parent component (i.e. using an in check).
- This method is invoked before any instances are created and thus
cannot rely on this.props. In addition, be aware that any complex
objects returned by
getDefaultProps()will be shared across instances, not copied.
getDefaultProps() is for Properties.
getInitialState() is for States.
getDefaultProps is for default props,if you don't inject this prop ,it will work .
getInitialState is for ini state,before the component is mounted.
In fact, what matter is the difference between props and state ,once you understand their differences, their default value's defference is easy to understand.
- what is the difference between getDefaultProps and getInitialState react js
- What is the difference between React Native and React?
- What is the difference between using constructor vs getInitialState in React / React Native?
- What is the difference between NextJs and Create React App
- What is the difference between hashHistory and browserHistory in react router?
- React Native - What is the difference between StyleSheet.absoluteFill() and StyleSheet.absoluteFillObject()?
- What is the main difference between React Query and Redux?
- React - What is the difference between renderToString and renderToStaticMarkup
- React Hooks: What is the difference between 'useMutationEffect' and 'useLayoutEffect'?
- What is the difference between React component instance property and state property?
- What is the difference between React component and React component instance?
- How does React router works and what is the difference between <link> and<Route>
- What is the difference between arrow functions and regular functions inside React functional components (no longer using class components)?
- ES6 React - What are the difference between reference, shallow copy and deep copy and how to compare them?
- What is the difference between useHistory() and props.history in React Route
- React Transition Group: What is the difference between the appear, enter, exit events and the enter, active done className suffixes?
- What is the difference between accessible, accessibilityLabel and accessibilityHint properties of Text component in react native?
- What is the real difference between value and defaultValue in React JS?
- What is the difference between React and Preact diff algorithm in depth
- What is the difference between a fibre object in React 16 and a React Element?
- What is the difference between Routing in React and Express
- What is the difference between passing a function name in onclick react and calling it through callback
- What is the difference between key and id in React component?
- what is the difference between React setState and Hooks setState?
- what is the difference between element attribute and component attribute in React <Route><Route/> tag
- What is the difference between function and functional React component?
- What is the difference between Nav.Link vs Link vs NavLink in react router DOM and react bootstrap?
- In React, what is the difference between using functional component and just a function, which returns React node?
- What is the difference between this.function and function call in React
More Query from same tag
- _firebase_js__WEBPACK_IMPORTED_MODULE_1__.firebase.auth.GoogleAuthProvider is not a constructor
- React rendering in a loop stops after first element
- How to make checkered chess board pattern with CSS
- react-simple-typewriter: Loop does not work
- How to change state of a component when the component is scrolled in view?
- how to return a user id from an express backend server
- How to create dynamic styled component?
- React router Link doesn't redirect
- Router only have one child component error
- react axios post generates json in array format. How to convert this to "name":"value" type format
- With a Styled-Components, how to set an array of colors outside of the Styled Component?
- Creating a ZxZ table in React/JSX using for loops
- How to fix 'React: Expected an assignment or function call and instead saw an expression'( state assignment)?
- How to display data fetched from Wordpress RestAPI in html format using React?
- I want to make overflow-x hidden and overflow-y visible
- React router has stuck to one component irrespective of URL
- Positioning CSS
- How can I solve TypeError: path.split is not a function
- Check prop values before loading component
- Middle URL Parameter in React Router
- How to pass a prop to a common component using react and typescript?
- Too many re-renders. React limits the number of renders to prevent an infinite loop. Updating state of a functional component inside the render method
- React Next.js - Three related questions about SSR patterns
- How to archive new build files in jenkins -pipeline script in groovy ReactJS
- React Bootstrap change link of Navbar to active
- CheckBox inside Formik form needs to be checked twice when a set state in handleChange is called
- React infinity state on console.log() using hooks why is that?
- react-apollo Query: Correct way to get the data from a <Query> Component
- TypeError: (...).map is not a function