-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate into a react project #22
Comments
@smotched I'm glad you like it! I've been meaning to put together a React component, but I haven't prioritized it yet since I primarily work in Vue. I'll try to get an example together for you soon. |
Something like the following might get you started: import { defineOptions, ink, Instance } from "ink-mde"
import { useEffect, useRef, useState } from "react"
type Props = {
content: string | null
onChange: (content: string) => void
readonly: boolean
}
const MarkdownEditor = ({ content, onChange, readonly }: Props) => {
const ref = useRef<HTMLDivElement | null>(null)
const [editor, setEditor] = useState<Instance | null>(null)
const options = defineOptions({
doc: content || undefined,
hooks: {
afterUpdate: onChange,
},
interface: {
readonly,
},
})
useEffect(() => {
if (ref.current && ref.current.children.length <= 0) {
const editor = ink(ref.current, options)
setEditor(editor)
}
}, [ref])
useEffect(() => {
if (editor) {
editor.reconfigure(options)
}
}, [readonly])
return <div ref={ref}></div>
}
export default MarkdownEditor |
Thanks for the example, @phylor! |
Hey @davidmyersdev , I have created a react project using ink-mde and the code by @phylor . Please check it, and if it seems fit, you can add it to the project for reference. This is my first open-source contribution, so let me know if I need to change any procedures for better convenience. |
Thanks for osing this neat library, is there a guide to integrating ink into an existing react project?
The text was updated successfully, but these errors were encountered: