Skip to content

Objects are not valid as a React child (found: [object Error]). #17

@mihaiicey

Description

@mihaiicey

Hi,
I have an error when I click to view a file created with Editor.js, the problem occurs only when there is a table in it, on the default it works fine.

Unhandled Runtime Error
Error: Objects are not valid as a React child (found: [object Error]). If you meant to render a collection of children, use an array instead.

The error when converting to HTML from string, on this page:


import { OutputData } from "@editorjs/editorjs";
import React from "react";
import editorJsHtml from "editorjs-html";
const EditorJsToHtml = editorJsHtml();

type Props = {
  data: OutputData;
};
type ParsedContent = string | JSX.Element;

const EditorJsRenderer = ({ data }: Props) => {
  const html = EditorJsToHtml.parse(data) as ParsedContent[];
  return (
    <div className="prose ContractTemplate max-w-full" key={data.time}>
      {html.map((item, index) => {
        if (typeof item === "string") {
          return (
            <div dangerouslySetInnerHTML={{ __html: item }} key={index}></div>
          );
        }
        return item;
      })}
    </div>
  );
};

export default EditorJsRenderer;

I think it's because you return: string[][]. To be honest I don't know how to fix this.
A little help?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions