-
Notifications
You must be signed in to change notification settings - Fork 114
Open
Labels
Description
I'm wrapping Winterfell with a component which accepts a prop role and use it to fetch schema data dynamically.
It seems like whenever Winterfell is rerendered, due to my wrapper component rerendering (due to prop change), it's questionAnswers state is being set to {};
Sample code:
/**
*
* RoleForm
*
*/
import React, { PropTypes } from 'react';
// import styled from 'styled-components';
import Winterfell from 'winterfell';
import { getRoleFormSchema } from './schemas';
// import { FormattedMessage } from 'react-intl';
// import messages from './messages';
class RoleForm extends React.PureComponent { // eslint-disable-line react/prefer-stateless-function
constructor(props) {
super(props);
this.state = {
schema: getRoleFormSchema(props.role),
};
}
shouldComponentUpdate() {
// TODO the moment Winterfell rerenders, it causes questionAnswers state to disappear
return false;
}
onFormRender() {
}
onFormUpdate() {
// TODO check for branch changes and clear data from supplied schema
// set a schema default value as undefined to clear it from the json payload on submit
console.log('update', arguments);
}
onFormSwitchPanel() {
}
onFormSubmit(questionAnswers, target) {
console.log('submit', arguments);
}
render() {
return (
<Winterfell
disableSubmit
schema={getRoleFormSchema()}
onRender={this.onFormRender}
onUpdate={this.onFormUpdate}
onSwitchPanel={this.onFormSwitchPanel}
onSubmit={this.onFormSubmit}
/>
);
}
}
RoleForm.propTypes = {
role: PropTypes.object,
};
export default RoleForm;
Debugger:
The problem will happen the moment I remove that shouldComponentUpdate block above.
