Skip to content

Commit

Permalink
Fix/child context type error (#88)
Browse files Browse the repository at this point in the history
* remove declaration of childContextTypes which cause React error

* bump version
  • Loading branch information
malcolm-kee authored Nov 9, 2021
1 parent ae62ee3 commit fe311e1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
33 changes: 13 additions & 20 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';

import * as ReactMobiledoc from '../src';
Expand All @@ -19,37 +18,31 @@ const config = {
const imgPayload = { caption: "Edit this right meow!", src: "http://www.placekitten.com/200/200" };


const ImageButton = (props, context) => {
const ImageButton = (props) => {
const { isEditing } = props;
const { editor } = context;
const { editor } = React.useContext(ReactMobiledoc.ReactMobileDocContext);

const onClick = () => editor.insertCard('ImageCard', imgPayload, isEditing);
return <button onClick={onClick}>Image Card</button>;
};

ImageButton.contextTypes = {
editor: PropTypes.object
};


const ClickCounterButton = (props, context) => {
const { editor } = context;
const ClickCounterButton = () => {
const { editor } = React.useContext(ReactMobiledoc.ReactMobileDocContext);
const onClick = () => editor.insertAtom('Counter', '', { clicks: 0 });
return <button onClick={onClick}>Click Counter Atom</button>;
};

ClickCounterButton.contextTypes = {
editor: PropTypes.object
};



ReactDOM.render(<ReactMobiledoc.Container {...config}>
<ReactMobiledoc.Toolbar />
<ImageButton />
<ClickCounterButton />
<ReactMobiledoc.Editor />
</ReactMobiledoc.Container>,
document.getElementById('root'));
ReactDOM.render(
<ReactMobiledoc.Container {...config}>
<ReactMobiledoc.Toolbar />
<ImageButton />
<ClickCounterButton />
<ReactMobiledoc.Editor />
</ReactMobiledoc.Container>,
document.getElementById('root')
);

require("!style-loader!css-loader!../node_modules/mobiledoc-kit/dist/mobiledoc.css");
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-mobiledoc-editor",
"version": "0.12.0",
"version": "0.12.1",
"description": "A Mobiledoc editor for React apps",
"repository": "joshfrench/react-mobiledoc-editor",
"homepage": "https://github.com/joshfrench/react-mobiledoc-editor",
Expand Down
7 changes: 0 additions & 7 deletions src/components/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ import { LATEST_MOBILEDOC_VERSION, EMPTY_MOBILEDOC } from '../utils/mobiledoc';
import { ReactMobileDocContext } from "./Context";

class Container extends React.Component {
static childContextTypes = {
editor: PropTypes.object,
activeMarkupTags: PropTypes.array,
activeSectionTags: PropTypes.array,
activeSectionAttributes: PropTypes.array
}

static defaultProps = {
atoms: [],
autofocus: true,
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { classToDOMCard } from './utils/classToCard';
import { classToDOMAtom } from './utils/classToAtom';
import { EMPTY_MOBILEDOC } from './utils/mobiledoc';
import Container from './components/Container';
import { ReactMobileDocContext } from "./components/Context";
import Editor from './components/Editor';
import LinkButton from './components/LinkButton';
import MarkupButton from './components/MarkupButton';
Expand All @@ -21,5 +22,6 @@ export {
AttributeSelect,
SectionButton,
SectionSelect,
Toolbar
Toolbar,
ReactMobileDocContext
};

0 comments on commit fe311e1

Please sign in to comment.