SFC.defaultProps = {渡したいprops}
でOK。
default_props.js
const AnySFC = (props) => (
<div>{props.defaultMessage}</div>
)
AnySFC.defaultProps = {
defaultMessage: 'デフォルトメッセージ',
};
デフォルトで何か style を当てつつ、style を変更したいときは props から変更できるようにする例。
style のプロパティをスプレッドシンタックスでマージしてます。
default_styled_sfc.jsx
import React from 'react';
const defaultProps = {
style: { color: 'red' },
};
const DefaultStyledSFC = (props) => (
<div {...props} style={{ ...defaultProps.style, ...props.style }}>
{props.children}
</div>
);
DefaultStyledSFC.defaultProps = defaultProps;
export default DefaultStyledSFC;
<DefaultStyledSFC style={{ color: 'green' }}>
などで上書き可能。