rajinwonderland / react-code-blocks

React code blocks and code snippet components
https://react-code-blocks.rajinwonderland.vercel.app
MIT License
613 stars 81 forks source link

"Cannot read properties of undefined (reading 'toString')" upon running CodeBlock #68

Closed LawrenceKurowski closed 1 year ago

LawrenceKurowski commented 2 years ago

Error when trying to use the solution described here.

Error message: TypeError: Cannot read properties of undefined (reading 'toString')

I copy-pasted the component exactly as is from here, installed the required library and included the import in the code, but can't make this to work as per error above.

roshambo919 commented 2 years ago

For me, this was because I was using the wrapper component MyCoolCodeBlock which uses the property "code" but I had mistakenly used a (non-existent) property "text". This was causing "null" to be passed into the "code" field. Solved by swapping property name.

cunguyendev commented 1 year ago

Hi, If you still got this issue, please import a theme for it. Let's check code below:

import { CopyBlock, monokai } from "react-code-blocks";
...

<CopyBlock
  language="bash"
  text={`your code`}
  theme={monokai}
/>

Because some properties are required inside the component.