question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can i use Draft with TypeScript?

See original GitHub issue

I install the Draft with npm, cmd: npm install --save draft-js, and install the @types command, cmd: npm install @types/draft-js --save, my TypeScript code is :

`class MyEditor extends React.Component<any, any> {
    constructor(props) {
        super(props);

        this.state = { editorState: EditorState.createEmpty() };
    }
    handleChange(e) {
        this.setState({ editorState: e });
    }
    render() {
        return (
            <Editor editorState={this.state.editorState} onChange={e => this.handleChange(e)} />
        );
    }
}

ReactDOM.render(
    <MyEditor />,
    document.getElementById('editor')
);`

But the IDE tell me: cannot find the name EditorState and Editor. How can i resolve it?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
cramheadcommented, Jan 13, 2017

Works for me with

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Editor, EditorState } from 'draft-js';

interface MyEditorProps {
}

class MyEditor extends React.Component<MyEditorProps, any> {
  constructor(props: MyEditorProps) {
    super(props);

    this.state = { editorState: EditorState.createEmpty() };
  }
  handleChange(e: EditorState) {
    this.setState({ editorState: e });
  }
  render() {
    return (
      <Editor editorState={this.state.editorState} onChange={e => this.handleChange(e)} />
    );
  }
}

ReactDOM.render(
  <MyEditor />,
  document.getElementById('editor'),
);

export { MyEditor }
1reaction
eelcocommented, Jan 9, 2017

import { Editor, EditorState } from "draft-js"

Read more comments on GitHub >

github_iconTop Results From Across the Web

@types/draft-js - npm
TypeScript definitions for Draft.js. Latest version: 0.11.10 ... Start using @types/draft-js in your project by running `npm i @types/draft-js`.
Read more >
@types/draft-js examples - CodeSandbox
Learn how to use @types/draft-js by viewing and forking example apps that make use of @types/draft-js on CodeSandbox. ; draft-js-editor ; editor.
Read more >
Rich editor for your react typescript project using hooks
Rich editor for your react typescript project using hooks. Add titles, images and links to your draft.js editor.
Read more >
Draft Js Mention Typescript (forked) - StackBlitz
React + TypeScript starter project. ... Draft Js Mention Typescript (forked) ... Compiling application & starting dev server…
Read more >
@types/draft-js | Yarn - Package Manager
0 vulnerabilities. TypeScript definitions for Draft.js ... Use it. $ yarn add @types/draft-js ... jsDelivr: cdn.jsdelivr.net/npm/@types/draft-js/.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found