I'm working with react storybook and wondering how can I set default props for a component?
My component within my app is a rail and fetches data - an image. This is set using {this.props.children}.
Within my rail component, I want to set default props so that the items still render if the data fetch fails.
Here is my component - scroll down the bottom for setting defaultProps:
import React, { Component } from 'react';
import './index.css'; // styles from
// import Slider from 'react-slick';
import classNames from 'classnames';
import PrimaryButton from '../PrimaryButton';
export default class HeroRail extends Component{
render() {
const {title, icon, opacity, railActive} = this.props;
const railStyle = {
opacity:opacity
};
const iconStyle = {
background: `center / contain url(${icon}) no-repeat`
};
const cName = classNames('HeroRail', {
railActive:railActive
});
console.log("props", this.props);
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>
);
}
};
HeroRail.defaultProps = {
};
Here is what the children prop looks like when a fetch is successful.
