Default props
defaultProps
can be used to set default values for props. To set default values for props, export a defaultProps
object from your component. This object will be merged with the props object passed to the component.
src/components/default-props.tsx
interface DefaultProps { text: string;}
export const defaultProps: DefaultProps = { text: "Hello, world!",};
export const component: DraymanComponent<DefaultProps> = async ({ props }) => { return () => { return ( <div> <div>{props.text}</div> </div> ); };};
In the example above, the text
prop is set to "Hello, world!"
by default. If you don't pass a text
prop to the component, it will use the default value.