Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jimmycode/draft-js-autosave-plugin

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jimmycode/draft-js-autosave-plugin

Autosave changes of your draft-js editor

  • 0.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by12.5%
Maintainers
3
Weekly downloads
 
Created
Source

draft-js-autosave-plugin

Build Status Coverage Status

Autosave changes of your draft-js editor.

This is a plugin for draft-js-plugins-editor.

Installation

npm install @jimmycode/draft-js-autosave-plugin

Usage

Instantiate the plugin passing the necessary config:

import createAutosavePlugin from '@jimmycode/draft-js-autosave-plugin';

const autosavePlugin = createAutosavePlugin(config);

And then pass the plugin into a draft-js-plugins-editor component:

import Editor from 'draft-js-plugins-editor';

<Editor
  plugins={[autosavePlugin]} />

Configuration

The config options and their defaults are:

OptionDefaultDescription
saveFunctionnullRequired callback function that will be called upon a save event.
debounceTime3000Time, in milliseconds, to debounce the firing of save events after changes.

Example

import React from 'react';
import ReactDOM from 'react-dom';

import { EditorState, convertToRaw } from 'draft-js';
import Editor from 'draft-js-plugins-editor';

import createAutosavePlugin from '@jimmycode/draft-js-autosave-plugin';

const saveDraft = (editorState) => {
  const rawContent = convertToRaw(editorState.getCurrentContent());
  localStorage.setItem('draft', JSON.stringify(rawContent));
}

const autosavePlugin = createAutosavePlugin({
  saveFunction: saveDraft,
  debounceTime: 3000
})

class MyEditor extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      editorState: EditorState.createEmpty()
    };
    this.plugins = [
      autosavePlugin
    ];
  }
  
  onChange = (editorState) => {
    this.setState({ editorState });
  }

  render() {
    return (
      <div className="editor">
        <Editor
          editorState={this.state.editorState}
          onChange={this.onChange}
          plugins={this.plugins}
          placeholder="Tell a story" />
      </div>
    );
  }
}

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

Acknowledge

https://www.npmjs.com/package/draft-js-autosave-plugin

Keywords

FAQs

Package last updated on 11 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc