Skip to content

Commit

Permalink
Remove unnecessary React.cloneElement (fix #159).
Browse files Browse the repository at this point in the history
  • Loading branch information
sapegin committed Jul 25, 2016
1 parent 3b110f4 commit 15da726
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/rsg-components/Preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ export default class Preview extends Component {

const exampleComponent = this.props.evalInContext(exampleComponentCode);

// Wrap everything in a react component, such that we can leverage the state management of this component
// Wrap everything in a react component to leverage the state management of this component
class PreviewComponent extends Component { // eslint-disable-line react/no-multi-comp
constructor(props) {
super(props);
constructor() {
super();

const state = {};
const initialStateCB = (initialState) => {
Expand All @@ -108,11 +108,7 @@ export default class Preview extends Component {
return <pre className={s.playgroundError}>{this.state.error}</pre>;
}

const setState = (nextState, callback) => this.setState(nextState, callback);
const state = this.state;

// Pass through props from the wrapper component
return React.cloneElement(exampleComponent(state, setState, null), this.props);
return exampleComponent(this.state, this.setState.bind(this), null);
}
}

Expand Down

1 comment on commit 15da726

@mik01aj
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. I have no idea why the props were needed in the first place.

Please sign in to comment.