Skip to content
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

JSX + React #1429

Merged
merged 10 commits into from
Jun 8, 2024
Merged

JSX + React #1429

merged 10 commits into from
Jun 8, 2024

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Jun 6, 2024

Extracted from #1216, this implements client-side support for JSX with React. It looks like this:

```jsx
import {Counter} from "./components/Counter.js";

display(<Counter title="Hello, JSX" />);
```

In JSX blocks, you can only display one thing at a time; subsequent calls to display will replace whatever was displayed previously. Also, you can only display React elements.

TODO:

  • JSX code blocks
  • JSX modules
  • React built-in
  • ReactDOM built-in
  • Handle syntax errors during JSX transpilation
  • Implicit (singular) createRoot within display
  • Documentation
  • Tests

Future work:

  • Allow JSX in inline expressions ${<Component />} (requires acorn-jsx)?
  • Allow JSX in Markdown directly (à la MDX)?

Fixes #971.

@mbostock mbostock requested a review from Fil June 6, 2024 15:12
package.json Outdated Show resolved Hide resolved
@mbostock mbostock force-pushed the mbostock/jsx branch 2 times, most recently from affee7d to db1df92 Compare June 6, 2024 16:05
@mbostock mbostock changed the title client-side JSX client-side JSX + React Jun 7, 2024
@mbostock mbostock marked this pull request as ready for review June 7, 2024 16:43
docs/jsx.md Outdated Show resolved Hide resolved
docs/jsx.md Outdated Show resolved Hide resolved
docs/jsx.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<OK />!

@mbostock mbostock changed the title client-side JSX + React JSX + React Jun 7, 2024
@mbostock
Copy link
Member Author

mbostock commented Jun 7, 2024

Hmm, I found a bug where if you move a JSX block to a new location during preview, it doesn’t get relocated (because we do the special treatment for root._nodes but that doesn’t apply to root._root). I think/hope I can fix that pretty easily though.

Edit: Fixed, but still working on the documentation and then I’ll push up some commits.

@mbostock mbostock enabled auto-merge (squash) June 8, 2024 00:42
@mbostock mbostock disabled auto-merge June 8, 2024 00:42
@mbostock mbostock enabled auto-merge (squash) June 8, 2024 00:47
@mbostock mbostock merged commit 0c72304 into main Jun 8, 2024
4 checks passed
@mbostock mbostock deleted the mbostock/jsx branch June 8, 2024 00:49
@mbostock mbostock mentioned this pull request Aug 18, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for JSX format as a Markdown alternative
2 participants