From 563ee0dae9d4421c7968c5c6f1e347d70ac645ed Mon Sep 17 00:00:00 2001 From: Michal Muzyk Date: Wed, 4 Oct 2023 15:46:59 +0200 Subject: [PATCH 1/2] feat: migrate onfido web component from class to functioncal --- src/components/Onfido/index.website.js | 43 ++++++++++++-------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/components/Onfido/index.website.js b/src/components/Onfido/index.website.js index 87bb92477dfa..910c8cad6440 100644 --- a/src/components/Onfido/index.website.js +++ b/src/components/Onfido/index.website.js @@ -1,34 +1,31 @@ -import React, {Component} from 'react'; +import React, {useEffect, useRef} from 'react'; import lodashGet from 'lodash/get'; import BaseOnfidoWeb from './BaseOnfidoWeb'; import onfidoPropTypes from './onfidoPropTypes'; -class Onfido extends Component { - constructor(props) { - super(props); - this.baseOnfido = null; - } +const Onfido = (props) => { + const baseOnfidoRef = useRef(null); - componentWillUnmount() { - const onfidoOut = lodashGet(this, 'baseOnfido.onfidoOut'); - if (!onfidoOut) { - return; - } + useEffect(() => { + return () => { + const onfidoOut = lodashGet(baseOnfidoRef.current, 'onfidoOut'); + if (!onfidoOut) { + return; + } - onfidoOut.tearDown(); - } + onfidoOut.tearDown(); + }; + }, []); - render() { - return ( - (this.baseOnfido = e)} - // eslint-disable-next-line react/jsx-props-no-spreading - {...this.props} - /> - ); - } -} + return ( + + ); +}; Onfido.propTypes = onfidoPropTypes; +Onfido.displayName = 'Onfido'; export default Onfido; From da85209db8ab6392ad111be90bb02174ce8cedfd Mon Sep 17 00:00:00 2001 From: Michal Muzyk Date: Thu, 5 Oct 2023 14:23:05 +0200 Subject: [PATCH 2/2] fix: cr fixes --- src/components/Onfido/index.website.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/components/Onfido/index.website.js b/src/components/Onfido/index.website.js index 910c8cad6440..23e59fb1e08f 100644 --- a/src/components/Onfido/index.website.js +++ b/src/components/Onfido/index.website.js @@ -3,27 +3,31 @@ import lodashGet from 'lodash/get'; import BaseOnfidoWeb from './BaseOnfidoWeb'; import onfidoPropTypes from './onfidoPropTypes'; -const Onfido = (props) => { +function Onfido({sdkToken, onSuccess, onError, onUserExit}) { const baseOnfidoRef = useRef(null); - useEffect(() => { - return () => { + useEffect( + () => () => { const onfidoOut = lodashGet(baseOnfidoRef.current, 'onfidoOut'); if (!onfidoOut) { return; } onfidoOut.tearDown(); - }; - }, []); + }, + [], + ); return ( ); -}; +} Onfido.propTypes = onfidoPropTypes; Onfido.displayName = 'Onfido';