-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Passing complex content into a react component into an mdx document. #474
Comments
This isn't very easy to achieve right now since MDX doesn't support embedding MD syntax inside JSX blocks. However, you can achieve something similar by breaking out the PracticeSchedule content into its own file:
Then, in You could also manipulate the children passed to |
if you go the child manipulation route, you could also use something likejsYaml in the react component itself to parse children from a string. It'd require the `` syntax for strings though.
|
jsYaml looks interesting...gonna try and get a basic version of the component working first, then will circle back around to this if it seems worth trying...thank you both! 😁 |
So here is how I am structuring my nested lists of content:
...and it logs fine in the console, but then I get this error message from react:
with a code highlight:
sooo, not sure what to do...should I just wrap the whole thing in an array? How would I do that? Not sure how that would work, to be honest. Could I simplify my data model as well? Would that be a wise idea...ano how I really do want to get markdown/yaml up in these react components XD |
Can you create a CodeSandbox with a reproduction? Sounds like your passing the object directly as children in PracticeSchedule. |
This is all I'm doing in the component thus far... import React from 'react'
const PracticeSchedule = (props) => {
console.log(props.schedule)
return (
<h1>{props.schedule}</h1>
)
}
export default PracticeSchedule; trying to figure out how to make a code sandbox as well... |
https://codesandbox.io/s/github/rchrdnsh/rykr ...will need to open up the render in a new window, cuz mobile styles aren't there yet, tho... |
Not sure where on the internet to ask this, so I figured I would start where it's trying to be done and see of anybody here has any ideas or resources to lead me towards. I'm desiring to make react components that can be used in mdx documents where I can feed them content like the following, which is sort of a simple YAML like syntax.
The preceding would be the desired author experience for a react component I'm working on that is a practice schedule for piano. I originally made a version of this in vanilla HTML and CSS and I tried tables and lists then but they didn't quite work for me in the styling department for various reasons, so I ended up making a series of divs with custom styling that ended up doing the job, but was all hand coded. So I desire to turn all that mess into a react component and feed it data in the preceeding manner, or something similar, that is keeping with the spirit of Markdown/YAML/MDX. I suppose I could feed the components props of arrays and objects filled with strings, but I would like to be able to keep the simple YAML/Markdown feel, even inside an instance of a react component. Does anybody know if something like this is even possible to do, and if so, would it be too much time/effort/trouble to implement?
The text was updated successfully, but these errors were encountered: