Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Default props #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

NickyMeuleman
Copy link

ref #13

Allows users to specify default props in gatsby-config.
These will be combined with the plugins default props.

Components will use the props passed to them in .mdx
If no props are specified in .mdx, the defaults in gatsby-config will be used.
If no props are specified in gatsby-config, the defaults set be the plugin will be used.

How

By adding a React context around the app in provider.
Individual components then access that context and merge the received props with the default ones (used via a custom React hook, useDefaultProps )

@NickyMeuleman
Copy link
Author

NickyMeuleman commented Feb 20, 2020

Added defaultprops to components that use them.
Typescript is showing errors because the returned type from the useDefaultProps hooks doesn't include the props that were not specified, but have a default.

Do you know how to accomplish that @PaulieScanlon?

edit: also the @pauliescanlon/gatsby-mdx-embed/hooks/useDefaultProps.js file is tracked, which is a generated file. Will have to remove that one from git tracking.
edit2: Removed some redudant typings of React Props.
Since React.FunctionComponent<IProps> is being used. The props do not need to be typed seperately, they already are by that <IProps> generic that is passed in.

FunctionComponent<IProps> typing definition below:

    interface FunctionComponent<P = {}> {
        (props: PropsWithChildren<P>, context?: any): ReactElement | null;
        propTypes?: WeakValidationMap<P>;
        contextTypes?: ValidationMap<any>;
        defaultProps?: Partial<P>;
        displayName?: string;
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant