Is this possible passing function to mdx file ?
See original GitHub issueHi,
Doing a page with ChakraUI, I’ve struggling for the whole day trying to passing function to mdx
file.
On the mdx file
, I was trying to achieve something like
<Image
src="xxx"
borderColor={useColorModeValue('gray.300', 'gray.700')}
borderWidth="1px"
shadow="md"
mb={8}
/>
The Image
component here is the https://chakra-ui.com/docs/media-and-icons/image chakraUI component.
And here is how I passed the useColorModeValue
function down(in tsx page):
import { useColorModeValue } from '@chakra-ui/react';
///...
const pageScecificComponent = {
...mdxComponents,
useColorModeValue // I'm struggling here
};
export const getStaticProps: GetStaticProps = async () => {
const postFilePath = path.join(POSTS_PATH, 'About.mdx');
const source = fs.readFileSync(postFilePath);
const { content, data } = matter(source);
const mdxSource = await serialize(content, {
// Optionally pass remark/rehype plugins
mdxOptions: {
remarkPlugins: [],
rehypePlugins: [],
},
scope: data,
});
return {
props: {
source: mdxSource,
frontMatter: data,
},
};
};
const Home: AppNextPage<InferGetStaticPropsType<typeof getStaticProps>> = ({ source, frontMatter }) => {
return <MDXRemote {...source} components={pageScecificComponent} />;
};
Everything was working fine if the useColorModeValue
function on mdx
file is not present.
So, is there anyway I can do this, googling things through various example but everything I found was it implemented using next-mdx-enhanced
(which I want to avoid).
I would appreciate even just some glue.
Thank you guys.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Getting started - MDX
This article explains how to integrate MDX into your project. It shows how to use MDX with your bundler and JSX runtime of...
Read more >How to /Can I export function to MDXProvider? #1120 - GitHub
I want to create and export some global utility function to MDX Context. ... could use rather than import it every time in...
Read more >Advanced Features: Using MDX - Next.js
MDX is a superset of markdown that lets you write JSX directly in your markdown files. It is a powerful way to add...
Read more >Guide to Writing MDX and Markdown | Chicago Docs
JSX attributes are passed to the React component as props. In an MDX file, a block of Markdown text between JSX tags is...
Read more >MDX - Storybook
MDX is a standard file format that combines Markdown with JSX. It means you can use Markdown's terse syntax (such as # heading)...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I did exactly as you re-correct the code… and magic happened 👍
Now this syntax worked:
Many thanks @jescalan, you made my day 🎉
Thanks for a quick reply @payapula,
I was though that was possible, but seems like I would take this approach as long as I could find anything that more helpful.
And ofcourse this should work right away. Have a good day 🎉