Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate onfido web component from class to functioncal #28815

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions src/components/Onfido/index.website.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
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;
}
function Onfido({sdkToken, onSuccess, onError, onUserExit}) {
const baseOnfidoRef = useRef(null);

componentWillUnmount() {
const onfidoOut = lodashGet(this, 'baseOnfido.onfidoOut');
if (!onfidoOut) {
return;
}
useEffect(
() => () => {
const onfidoOut = lodashGet(baseOnfidoRef.current, 'onfidoOut');
if (!onfidoOut) {
return;
}

onfidoOut.tearDown();
}
onfidoOut.tearDown();
},
[],
);

render() {
return (
<BaseOnfidoWeb
ref={(e) => (this.baseOnfido = e)}
// eslint-disable-next-line react/jsx-props-no-spreading
{...this.props}
/>
);
}
return (
<BaseOnfidoWeb
ref={baseOnfidoRef}
sdkToken={sdkToken}
onSuccess={onSuccess}
onError={onError}
onUserExit={onUserExit}
/>
);
}

Onfido.propTypes = onfidoPropTypes;
Onfido.displayName = 'Onfido';

export default Onfido;
Loading