props key returns empty object from scope
See original GitHub issueHi there
Have found that using the props
key in next-mdx-remote
’s scope
property always returns an empty object
See this example: https://codesandbox.io/s/next-mdx-remote-props-s85i4?file=/pages/index.js
props.title
returns undefined
, but props2.title
returns as expected. props
does however return an empty object.
Could there be something overwriting it somewhere in MDX, or is it somehow a reserved word?
Would ideally like to use the props.
notation in MDX pages as it’s familiar from the React ecosystem.
Any help appreciated. Thanks
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Prop from parent component returns empty on one of the childs
I found the problem, on the GSearchVehicle component my memoized functions were missing the positions prop on it's dependencies.
Read more >How to Check If an Object is Empty in JavaScript? - Scaler
If the method returns an empty array, then it means the given object is empty as it has no keys. This way we...
Read more >JavaScript: Check if an Object is Empty - Stack Abuse
keys () is a static method that returns an Array when we pass an object to it, which contains the property names (keys)...
Read more >typescript-cheatsheet - GitHub Pages
argument types function multiply(value1: number, value2: number) { return ... In JavaScript, so as in TypeScript, Objects are comprised of key-value pairs.
Read more >JSX In Depth - React
createElement , the React library must also always be in scope from your JSX code. ... JSX type can't be an expression. return...
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
Okay I’ve done a bit of poking around and I came up with a solution that works, though you may not like it. To bypass the shadowing issue, I think we can simply use the
props
that are passed toMDXContent
. I think this intuitively makes sense since we are trying to passprops
to the component, so we may as well use the front door rather than the window. For example, if we change the hydration fromsrc/index.tsx
:This will extract any
props
fromscope
and inject them into the MDX component via the traditional route. I tested this as a hack via my browser debugger but I’ll look into forking this and testing it as a full-fledged change. I think in reality it may make more sense to add aprops: P
field toMDXRemoteProps<P>
and add type parameter<P = {}>
toMDXRemote
.@BRKalow I’ve opened a PR for this, please take a look.