Skip to content

Uncaught Error: Objects are not valid as a React child #74

Open

Description

@peter-reonomy

Current behaviour

After upgrading my Gatsby project dependencies, the editor won't render any text (get Uncaught Error: Objects are not valid as a React child). Everything was working great before. The only thing that doesn't cause a crash is an empty string as the value. As son as I set the value to something as simple as 'test' it crashes.

Expected behaviour

Uncaught Error: Objects are not valid as a React child (found: object with keys {type, value}). If you meant to render a collection of children, use an array instead. in pre (created by Editor) in div (created by Editor) in Editor (at test.tsx:18) in div (at test.tsx:17) in Test (created by HotExportedTest)

Code sample

import React, { useState } from 'react';

import Editor from 'react-simple-code-editor';
// @ts-ignore
import { highlight, languages } from 'prismjs/components/prism-core';

export const Test = () => {

const [text, setText] = useState('');

const onCodeChanged = (code: string) => {
setText(code);
}

return (
<div style={{border: '1px solid gray', height: 100}}>
<Editor
value={text}
onValueChange={code => onCodeChanged(code)}
highlight={code => highlight(code, languages.json)}
padding={10}
className="container__editor"
style={{
fontFamily: 'Menlo, Consolas, "Courier New", monospace',
fontSize: 13,
whiteSpace: 'pre'
}}
/>

)
}

export default Test;

Screenshots (if applicable)

What have you tried

Your Environment

software version
react-simple-code-editor 0.11.0
react 16.13.1
npm or yarn yarn 1.22.4
node 13.11.0
browser chrome

Activity

  1. Yuri6037 commented on Dec 16, 2020

    @Yuri6037

    Hi I just got hit by this error and found a way to fix it. The problem seam to be related to prismjs. prismjs apparently for some reasons decided it wanted to f*** ** every projects by no longer generating any HTML code but instead returning a crappy non-sense list of objects.

    In order to fix it just locate the line that mentions prismjs in your package.json and replace it with:

    "prismjs": "1.20.0",

    Notice the remove '^' character.

    I have tested this fix on both yarn and npm and it worked on both.

  2. saswat3115 commented on May 12, 2021

    @saswat3115

    after doing above step I am getting below error

    ×
    ReferenceError: Prism is not defined

  3. bhavaniravi commented on Jun 20, 2021

    @bhavaniravi

    @saswat3115 you might want to reinstall the npm package with the correct version after changing package.json

    Thank you @Yuri6037, I was stuck with this for hours

  4. gmarathiarcadix commented on Mar 20, 2023

    @gmarathiarcadix

    Hi I just got hit by this error and found a way to fix it. The problem seam to be related to prismjs. prismjs apparently for some reasons decided it wanted to f*** ** every projects by no longer generating any HTML code but instead returning a crappy non-sense list of objects.

    In order to fix it just locate the line that mentions prismjs in your package.json and replace it with:

    "prismjs": "1.20.0",

    Notice the remove '^' character.

    I have tested this fix on both yarn and npm and it worked on both.

    Nope, not working for me , even after making the above changes .

  5. bhavaniravi commented on Mar 20, 2023

    @bhavaniravi

    @gmarathiarcadix you need to do an npm uninstall prismjs and then reinstall using npm install

  6. gmarathiarcadix commented on Mar 20, 2023

    @gmarathiarcadix

    @gmarathiarcadix you need to do an npm uninstall prismjs and then reinstall using npm install

    did the same thing

    1. uninstalled prismjs

    2. added --> "prismjs": "1.20.0", this line in the pacakge.json

    3. and then issued this cmd -> npm install

    i'm using --> "react": "^18.1.0", ( hoope that is fine )

    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions