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.

Value to React view

See original GitHub issue

Do you want to request a feature or report a bug?

Feature

What’s the current behavior?

If you want to display rich text edited by Slate in React, you have to use the html serializer, and then put it as the html content of some div. If you want to use a custom component, you can’t do this.

It would be great if there was a stripped-down “react serializer component” that takes a value (result of .toJSON()) and some rules and then can be used as a regular component.

It would be even greater if it would not need Immutable to do this.

What’s the expected behavior?

<SlateValue value={value} rules={rules} /> puts the edited text where it’s mounted, using the components defined in the rules.

If there is already something like this somewhere, it would be great if that could be made into a package for slate.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
wmertenscommented, Jul 6, 2018

We made slateToReact.js which converts from slate JSON representation to a React tree.

  • This is mostly the serialize logic from slate-html-serializer, except that it works on the JSON and not the Immutable object.
    • In particular, it doesn’t call getLeaves but just uses the leaves array
  • I wonder if maybe this code can be factored out somehow? I’d love to see this be part of the Slate packages
  • Will the JSON representation change in the future?
    • In particular, it seems to be rather wordy and it keeps all the empty objects and arrays.
    • It would be nice if the JSON could be made more compact and get a version field so that parsers know if/how they are supposed to parse this.
    • I also wonder if the JSON structure could be memoized, since it gets built on every keystroke.
0reactions
ianstormtaylorcommented, Nov 28, 2019

I believe that this may be fixed by https://github.com/ianstormtaylor/slate/pull/3093, which has changed a lot of the logic in Slate and slate-react especially. I’m going to close this out, but as always, feel free to open a new issue if it persists for you. Thanks for understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Displaying Data | React
The most basic thing you can do with a UI is display some data. React makes it easy to display data and automatically...
Read more >
View - React Native
Represents the current value of a component. It can be a textual description of a component's value, or for range-based components, such as ......
Read more >
Components and Props - React
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation. This page provides an introduction to...
Read more >
Component State - React
What does setState do? setState() schedules an update to a component's state object. When state changes, the component responds by re-rendering.
Read more >
Thinking in React
React is, in our opinion, the premier way to build big, fast Web apps with JavaScript. It has scaled very well for us...
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