Comments (7)
@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.
@OmarZeidan Upgrade + @uiw/[email protected]
from react-codemirror.
@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.
@OmarZeidan Can you give me an example, let me debug it?
from react-codemirror.
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.
@Gnarus-G Exmaple: https://codesandbox.io/s/nextjs-example-react-codemirror-bimq7?file=/pages/index.js
from react-codemirror.
@jaywcjlove Oh man, I appreciate you. I learned a lot from this. Thank you.
from react-codemirror.
Related Issues (20)
- Manually set cursor position
- [ Indentation ]: Auto indent after for/while loops HOT 1
- Disable autocompletion keymap HOT 1
- New theme for console/terminal view? HOT 4
- Custom JS keyboard HOT 5
- Fix error related to "Types must be imported using a type-only import when 'verbatimModuleSyntax' is enabled" HOT 2
- Css lint HOT 1
- How to change the font HOT 5
- Unable to use browser's selection API when text in the editor is long enough HOT 3
- 父组件必须确定高度才能设定CodeMirror高度100%? HOT 4
- No SSR support (Remix): React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. HOT 2
- How do you map changes between a CodeMirror component and an array of objects?
- Nord Theme: A comment for a selected line is not visible HOT 1
- How to remove dotted line on focus? HOT 3
- Is it possible to use the themes from this project with CodeMirror 6 without using React? HOT 1
- How to show Tooltips in react-codemirror HOT 2
- How to add a lint panel? HOT 1
- How To Disable Copy Paste in Editor? HOT 3
- Font size in theme settings HOT 2
- code highlighting HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-codemirror.