Skip to content

Commit

Permalink
fixing listener use on component lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabiana Fonseca committed Oct 7, 2020
1 parent 2ec840d commit 91fdca6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
15 changes: 10 additions & 5 deletions react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ class CheckoutButtonExample extends Component<{}, CheckoutButtonExampleState> {
}
}

listenOrderFormUpdated() {
$(window).on('orderFormUpdated.vtex', (_: any, orderForm: OrderForm) =>
this.setState({ orderForm })
)
setOrderForm = (_: any, orderForm: OrderForm) => {
this.setState({ orderForm })
}

componentDidMount() {
$(window).on('orderFormUpdated.vtex', this.setOrderForm)
}

componentWillUnmount() {
$(window).off('orderFormUpdated.vtex', this.setOrderForm)
}

render() {
this.listenOrderFormUpdated()
console.log(window.vtex.i18n.getLocale())

return <CustomButton {...this.state.orderForm!} />
Expand Down
2 changes: 1 addition & 1 deletion react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"react-apollo": "^2.0.4",
"react-dom": "^16.2.0",
"react-intl": "^2.4.0",
"typescript": "3.8.3"
"typescript": "3.9.7"
}
}
8 changes: 4 additions & 4 deletions react/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2525,10 +2525,10 @@ typed-styles@^0.0.7:
resolved "https://registry.yarnpkg.com/typed-styles/-/typed-styles-0.0.7.tgz#93392a008794c4595119ff62dde6809dbc40a3d9"
integrity sha512-pzP0PWoZUhsECYjABgCGQlRGL1n7tOHsgwYv3oIiEpJwGhFTuty/YNeduxQYzXXa3Ge5BdT6sHYIQYpl4uJ+5Q==

typescript@3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==
typescript@3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==

uncontrollable@^6.0.0:
version "6.2.3"
Expand Down

0 comments on commit 91fdca6

Please sign in to comment.