From a9bab1b52d652131af2797a8046c63a8a311816e Mon Sep 17 00:00:00 2001 From: Muhammed Thanish Date: Fri, 26 Aug 2016 10:13:05 +0530 Subject: [PATCH] Validate storyFn property in StoryView Fixes #57 --- dist/preview/components/StoryView/index.js | 7 ++++--- src/preview/components/StoryView/index.js | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/dist/preview/components/StoryView/index.js b/dist/preview/components/StoryView/index.js index d72d708..c6b1347 100644 --- a/dist/preview/components/StoryView/index.js +++ b/dist/preview/components/StoryView/index.js @@ -44,9 +44,7 @@ var StoryView = function (_Component) { var _this = (0, _possibleConstructorReturn3.default)(this, (_ref = StoryView.__proto__ || (0, _getPrototypeOf2.default)(StoryView)).call.apply(_ref, [this, props].concat(args))); - _this.state = { storyFn: function storyFn() { - return null; - } }; + _this.state = { storyFn: null }; _this.props.events.on('story', function (storyFn) { return _this.setState({ storyFn: storyFn }); }); @@ -56,6 +54,9 @@ var StoryView = function (_Component) { (0, _createClass3.default)(StoryView, [{ key: 'render', value: function render() { + if (!this.state.storyFn) { + return null; + } return this.state.storyFn(); } }]); diff --git a/src/preview/components/StoryView/index.js b/src/preview/components/StoryView/index.js index 40dfd8a..25e6302 100644 --- a/src/preview/components/StoryView/index.js +++ b/src/preview/components/StoryView/index.js @@ -3,11 +3,14 @@ import React, { Component } from 'react'; export default class StoryView extends Component { constructor(props, ...args) { super(props, ...args); - this.state = {storyFn: () => null}; + this.state = {storyFn: null}; this.props.events.on('story', storyFn => this.setState({storyFn})); } render() { + if (!this.state.storyFn) { + return null; + } return this.state.storyFn(); } }