score:0
one way to slove the issue is to use static propTypes
static propTypes = {
children: PropTypes.node.isRequired,
}
another way to slove the issue wish i recomend , is to not render the component unless you have fetched the value
if(!this.props.children){
return(<div>Loading ....... </div>
}
return (
<div className={cName} style={railStyle}>
<div className={'rail-details'}>
<div className={'top-details'}>
<div className={'title-lockup'}>
<div className={'icon'} style={iconStyle}></div>
<h3 className={'rail-title'}>{title}</h3>
</div>
<PrimaryButton label={'View All'} light={true}/>
</div>
<div className={'rail-navigation'}>
<PrimaryButton icon='' light={true} />
<PrimaryButton icon='' light={true} />
</div>
</div>
<div className={'rail-items'}>
{this.props.children}
</div>
</div>
);
score:0
One way of solving this is to import the 'prop-types' component see the following example:-
import PropTypes from 'prop-types';
const propertyType = ({[name_of_property]}) => {
<div><h1>{name_of_property}</h1></div>
};
propertyType.propTypes = {
[name_of_property]: PropTypes.string,
};
propertyType.defaultProps ={
[name_of_property]: [default_value],
};
read this when you can : https://www.npmjs.com/package/prop-types
score:1
You can set the default props using the class name as shown below.
class Greeting extends React.Component {
render() {
return (
<h1>Hello, {this.props.name}</h1>
);
}
}
// Specifies the default values for props:
Greeting.defaultProps = {
name: 'Stranger'
};
You may refer this link from react's documentation for more info.
Source: stackoverflow.com
Related Query
- How to set component default props on React component
- How to set React default props for object type
- Set default props for a react Component
- React - Array of children components not rerendering with props expression set in a callback
- React Set Default Props on this.props.children
- How can I set default values for props on a React TypeScript component?
- Where can I find the API guide for this usage of passing props to children in React
- React functional component default props vs default parameters
- How to specify (optional) default props with TypeScript for stateless, functional React components?
- React props - set isRequired on a prop if another prop is null / empty
- Accessing React component children props from the parent
- How to declare default props in react functional component
- Passing props to React Router children routes
- React changing props on grandchildren: object is not extensible / tree traversing react children
- How to set React component state and props from browser
- React JSX: How to set props to placeholder attribute
- Set Heading Level With Props React
- Typescript: how to set type of children in React Component?
- Typing a React component that clones its children to add extra props in TypeScript
- How to test default props functions is attached to component or not ? | React | Jest | Enzyme
- What TypeScript type should React children be set to?
- React dynamic default props
- Pass two children as props to a React component
- Can't set props to state using useState React
- React - How to set default value in react-select
- Passing props from react router to children on the server
- Why cant react set initial state based on props
- React what's the right way to get a parent props from its children
- unable set a default value in redux-form w. react
- React js: How to set props in JSX components which store in variable
More Query from same tag
- How to send a message to everyone execpt the sender socket.io
- TypeScript: is there a way to parameterize an enum
- React Iterate and insert components based on count of array
- Why do we have interfaces and initialstates in React and typescript for Redux tool kit?
- Javascript compare two complex objects
- Is it possible to concatenate an img src in React?
- How to get Responsiveness for the mobile approach for the code using media queries
- React Material UI Collapse
- React Router renders the target page on the same page
- Axios is undefined in React, error: Uncaught TypeError: Cannot read property 'post' of undefined
- Comprhension about useState (React)
- chess.js: Move validation not working correctly
- How to filter date events in mongoose?
- Laravel Mix - Integrate web3 react app into laravel
- React-js service worker cache issue
- React Redux - Pass data from state to another component to display list of results
- React: What happens on consecutive renders where a list shuffles?
- How to use Axios cancelToken in interceptors?
- JSX inside ternary not returning desired result
- Link card area that contains a button
- How to show files in browser with DataUrl format?
- Place icon right next to it and in the center
- How to compare two big arrays of objects on identity
- Ant Design table continues to show loading even when the table is populated by data
- Why I'm getting these warnings while using useEffect hook in React.js?
- React useEffect hook and eslint warning
- React Component vote up and down
- Trying to render an API call inside of a mapped Array
- Style not updating in component - React
- how to prevent react-router-dom nested routes to get confused with route params