Giter VIP home page Giter VIP logo

Comments (7)

jaywcjlove avatar jaywcjlove commented on May 18, 2024 1

@Gnarus-G Since codemirror does not support server-side rendering, it is a bit strange to implement. Upgrade + @uiw/[email protected]

import { useEffect, useState } from 'react';

function HomePage() {
  const [comp, setComp] = useState();
  useEffect(() => {
    if (window) {
      import('@uiw/react-codemirror').then((obj) => {
        if (!comp) {
          setComp(obj.default);
        }
      });
    }
  }, []);

  const Comps = comp;
  return (
    <div>
      <div>Welcome to Next.js!</div>
      {Comps && (
        <Comps
          value="const a = 0;"
          options={{
            mode: "jsx",
          }}
        />
      )}
    </div>
  )
}

export default HomePage
$ yarn add @zeit/next-css

Add next.config.js

const withCSS = require('@zeit/next-css');

module.exports = withCSS({
  // Your configurations here
});

from react-codemirror.

jaywcjlove avatar jaywcjlove commented on May 18, 2024

@OmarZeidan Upgrade + @uiw/[email protected]

from react-codemirror.

OmarZeidan avatar OmarZeidan commented on May 18, 2024

@jaywcjlove Thanks but the same error!

Look inside /lib/esm/index.js file of your compiled version, and you will notice

import './codemirror.css';
import './index.css';

Which will def be causing the error for next.js framework and Global CSS dilemma!

from react-codemirror.

jaywcjlove avatar jaywcjlove commented on May 18, 2024

@OmarZeidan Can you give me an example, let me debug it?

from react-codemirror.

Gnarus-G avatar Gnarus-G commented on May 18, 2024

Next.js says this, when I try to use the component.

error - ./node_modules/@uiw/react-codemirror/lib/esm/codemirror.css
Global CSS cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-npm
Location: node_modules/@uiw/react-codemirror/lib/esm/index.js

Is this a good example? Try to render this component.

import Codemirror from "@uiw/react-codemirror";

export default function CodeEditor() {

    function onChange(instance: CodeMirror.Editor, change: CodeMirror.EditorChangeLinkedList[]) {
        console.log('instance :>> ', instance.getValue);
    }

    return <Codemirror
        options={{
            theme: 'monokai',
            keyMap: 'sublime',
            mode: 'jsx',
        }}
        onChange={onChange}
    />
}

from react-codemirror.

jaywcjlove avatar jaywcjlove commented on May 18, 2024

@Gnarus-G Exmaple: https://codesandbox.io/s/nextjs-example-react-codemirror-bimq7?file=/pages/index.js

from react-codemirror.

Gnarus-G avatar Gnarus-G commented on May 18, 2024

@jaywcjlove Oh man, I appreciate you. I learned a lot from this. Thank you.

from react-codemirror.

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.