@mdx-js/react#useMDXComponents JavaScript Examples

The following examples show how to use @mdx-js/react#useMDXComponents. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: root-state.jsx    From MDXP with MIT License 6 votes vote down vote up
RootState = ({children, ...props}) => {
  const shortCodeComponents = useMDXComponents();
  const [state, setState] = useMerger({
    shortCodeComponents,
    previousMode: deckModes.NORMAL,
    ...props
  });

  return (
    <RootContext.Provider value={[state, setState]}>
      {children}
    </RootContext.Provider>
  );
}
Example #2
Source File: wrapper.jsx    From MDXP with MIT License 6 votes vote down vote up
wrapper = (DefaultLayout, passedProps, components) => {
  const slideCreator = createSlideComponent(DefaultLayout);

  return props => {
    const mdxComponents = useMDXComponents();
    const shortCodeComponents = components || mdxComponents;
    const children = React.Children.toArray(props.children);

    const extracted = [];
    const extractor = extractComponents(extracted, shortCodeComponents);

    const slides =
      splitSlides(children, shortCodeComponents)
        .filter(slideObject => slideObject.elements.length > 0)
        .map(extractor)
        .map((slideObject, idx) => slideCreator(slideObject, `layout_${idx}`, shortCodeComponents));

    return (
      <DeckMode extracted={extracted} {...passedProps}>
        {slides}
      </DeckMode>
    );
  };
}