question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to /Can I export function to MDXProvider?

See original GitHub issue

I cannot find from the documentation.

I want to create and export some global utility function to MDX Context. Like the following codes:

function plusOne(a) {
  return a + 1
}

<MDXProvider functions={{ plusOne }}>
    <MDXRenderer>{some.body}</MDXRenderer>
</MDXProvider>

some.mdx

# H1

Some content

<Comp value={plusOne(10)} />

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wooormcommented, Nov 13, 2020

Why would that be a good idea? React also doesn’t let you access some global state in all your files 🤷‍♂️

0reactions
gaplo917commented, Nov 14, 2020

Faithfully, the current MDX gives the existing markdown writer to have an opportunity to write something encapsulate, expressive, and declarative. I do think the reason of “why you have a chance to register a component in instead of import every time” is that

@gaplo917 please read the example before commenting. Functions can be passed in, without importing, using props https://codesandbox.io/s/funny-grass-ce9cb?file=/src/hello.mdx

Ops, the previous version example you wrote don’t use a props but import.

That’s probably a new way for my MDX components design, Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using MDX
This article explains how to use MDX files in your project. It shows how you can pass props and how to import, define,...
Read more >
@mdx-js/react - unified
import {MDXProvider} from '@mdx-js/react' import Post from '. ... Additional components ( Components ) to use or a function that takes the current ......
Read more >
Customizing Markdown Components - Gatsby
import { MDXProvider } from "@mdx-js/react". import * as DesignSystem from "your-design-system". export default function Layout({ children }) {. return (.
Read more >
Advanced Features: Using MDX - Next.js
pages/index.js import { MDXProvider } from '@mdx-js/react' import Image from 'next/image' ... export default function Post(props) { return ( <MDXProvider ...
Read more >
MDX and React - Docusaurus
You can also import your own components defined in other files or third-party ... export default function Highlight({children, color}) {
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found