GithubHelp home page GithubHelp logo

ReactNative support about redraft HOT 7 CLOSED

lokiuz avatar lokiuz commented on July 17, 2024 1
ReactNative support

from redraft.

Comments (7)

lokiuz avatar lokiuz commented on July 17, 2024

Didn't have a chance to test it myself yet as I only played around with RN a bit, but it should work just fine. Redraft itself doesn't have any React specific code/dependencies.

Might be a good idea to test it and add some info to readme.

from redraft.

mxstbr avatar mxstbr commented on July 17, 2024

Running into the first issue:

screen shot 2018-01-22 at 11 07 55

How can I make sure that redraft never returns just a string? In ReactNative you have to wrap every string in a Text component.

This is what my renderer look like so far:

import React from 'react';
import Text from '../components/Text';

const renderer = {
  blocks: {
    unstyled: (children, { keys }) =>
      children.map((child, index) => (
        <Text key={keys[index] || index}>{child}</Text>
      )),
    'header-one': (children, { keys }) =>
      children.map((child, index) => (
        <Text type="title1" key={keys[index] || index}>{child}</Text>
      )),
    'header-two': (children, { keys }) =>
      children.map((child, index) => (
        <Text type="title2" key={keys[index] || index}>{child}</Text>
      )),
  },
};

from redraft.

mxstbr avatar mxstbr commented on July 17, 2024

Worked around this for now by doing

const filterStrings = (array) => {
  const items = [];
  array.forEach(item => {
    if (typeof item === 'string') return;
    if (Array.isArray(item)) return items.push(filterStrings(item));

    items.push(item);
  })

  return items;
}

filterStrings(redraft(state, renderer));

The solution to this could be an option to wrap each unknown type in an unstyled block maybe? That would work for our use case.

from redraft.

lokiuz avatar lokiuz commented on July 17, 2024

If I understand this correctly your raw contains a block that doesn't have a corresponding renderer which results in the block being returned as a string.

Falling back to unstyled might be an option, or possibly allow to define a custom fallback type.

from redraft.

mxstbr avatar mxstbr commented on July 17, 2024

Yesss, that is perfect! Did you release the blockFallback option already?

from redraft.

lokiuz avatar lokiuz commented on July 17, 2024

I just did 0.10.0 release as this changes the default behavior. Should I close this for now?

from redraft.

mxstbr avatar mxstbr commented on July 17, 2024

Sounds good!

from redraft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.