Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
remove ref from for get the data in TargetContainer
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjayradadiya authored and norbertschuler committed Sep 28, 2020
1 parent 23be877 commit 6b3af40
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
5 changes: 3 additions & 2 deletions app/components/Target/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class Target extends Component {
label: countTarget !== 0 ? i18n.t('label.update') : i18n.t('label.save'),
initialValues: { countTarget, targetYear, targetComment }
};
this.formRef=React.createRef();
}
shouldComponentUpdate(nextProps) {
return JSON.stringify(nextProps) !== JSON.stringify(this.props);
Expand All @@ -52,12 +53,12 @@ export default class Target extends Component {
<TextHeading>{i18n.t('label.set_target')}</TextHeading>
<CardLayout>
<TCombForm
ref="setTargetForm"
ref={this.formRef}
type={targetFormSchema}
options={allSchemaOptions}
value={this.state.initialValues}
/>
<PrimaryButton onClick={this.props.onSubmitTarget}>
<PrimaryButton onClick={()=>this.props.onSubmitTarget(this.formRef.current)}>
{this.state.label}
</PrimaryButton>
</CardLayout>
Expand Down
5 changes: 3 additions & 2 deletions app/components/Target/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class Target extends Component {
this.state = {
label: countTarget !== 0 ? i18n.t('label.update') : i18n.t('label.save')
};
this.formRef=React.createRef();
}

shouldComponentUpdate(nextProps) {
Expand All @@ -37,14 +38,14 @@ export default class Target extends Component {
style={{ flex: 1, marginTop: Platform.OS === 'ios' ? 140 : 100 }}
>
<Form
ref={'setTargetForm'}
ref={this.formRef}
type={targetFormSchema}
options={this.props.schemaOptions}
value={this.props.treecounter}
/>
</CardLayout>
<PrimaryButton
onClick={this.props.onSubmitTarget}
onClick={()=>this.props.onSubmitTarget(this.formRef.current)}
buttonStyle={{ marginTop: 10 }}
>
{this.state.label}
Expand Down
13 changes: 3 additions & 10 deletions app/containers/TargetContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ class TargetContainer extends React.Component {
};
this.onSubmitTarget = this.onSubmitTarget.bind(this);
}
onSubmitTarget = () => {
/* debug(
'\x1b[45m targetCOntainer',
this.refs.targetContainer.refs.setTargetForm.validate
); */
//debug('\x1b[0m');
//debug(this.refs.targetContainer.refs.setTargetForm.validate());
let value = this.refs.targetContainer.refs.setTargetForm.getValue();
onSubmitTarget = (formRef) => {
let value = formRef.getValue();
if (value) {
this.props
.SubmitTarget(value, this.props.navigation)
Expand All @@ -41,7 +35,7 @@ class TargetContainer extends React.Component {
}
},
() => {
this.refs.targetContainer.refs.setTargetForm.validate();
formRef.validate();
}
);
});
Expand All @@ -51,7 +45,6 @@ class TargetContainer extends React.Component {
render() {
return (
<Target
ref={'targetContainer'}
treecounter={this.props.treecounter}
schemaOptions={this.state.schemaOptions}
onSubmitTarget={this.onSubmitTarget}
Expand Down

0 comments on commit 6b3af40

Please sign in to comment.