Skip to content

Commit

Permalink
Move to componentDidMount, fixes #220
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonkle committed Oct 1, 2020
1 parent 00ca573 commit f422428
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/components/Live/LiveProvider.js
Expand Up @@ -4,6 +4,8 @@ import PropTypes from 'prop-types';
import LiveContext from './LiveContext';
import { generateElement, renderElementAsync } from '../../utils/transpile';

const EMPTY_STATE = { unsafeWrapperError: undefined, error: undefined };

export default class LiveProvider extends Component {
static defaultProps = {
code: '',
Expand All @@ -23,8 +25,9 @@ export default class LiveProvider extends Component {
transformCode: PropTypes.node
};

// eslint-disable-next-line camelcase
UNSAFE_componentWillMount() {
state = EMPTY_STATE;

componentDidMount() {
const { code, scope, transformCode, noInline } = this.props;

this.transpile({ code, scope, transformCode, noInline });
Expand Down Expand Up @@ -65,20 +68,17 @@ export default class LiveProvider extends Component {

const errorCallback = err =>
this.setState({ element: undefined, error: err.toString() });
const renderElement = element => this.setState({ ...state, element });

// State reset object
const state = { unsafeWrapperError: undefined, error: undefined };
const renderElement = element => this.setState({ ...EMPTY_STATE, element });

try {
if (noInline) {
this.setState({ ...state, element: null }); // Reset output for async (no inline) evaluation
this.setState({ ...EMPTY_STATE, element: null }); // Reset output for async (no inline) evaluation
renderElementAsync(input, renderElement, errorCallback);
} else {
renderElement(generateElement(input, errorCallback));
}
} catch (error) {
this.setState({ ...state, error: error.toString() });
this.setState({ ...EMPTY_STATE, error: error.toString() });
}
};

Expand Down

0 comments on commit f422428

Please sign in to comment.