fix: stabilize the identity of the context provider value (#251)

This commit is contained in:
Jonathan Baudanza authored and GitHub committed 2022-01-10 13:17:25 -06:00
1 parent bd0c001215
commit 55005ba0fb
1 file changed
+11 -8
+11 -8
View File
@@ -2,7 +2,7 @@ import * as React from 'react';
import ActionSheet from './ActionSheet';
import { Provider } from './context';
import { ActionSheetOptions } from './types';
import { ActionSheetOptions, ActionSheetProps } from './types';
interface Props {
children: React.ReactNode;
@@ -11,24 +11,27 @@ interface Props {
export default class ActionSheetProvider extends React.Component<Props> {
_actionSheetRef: React.RefObject<ActionSheet>;
_context: ActionSheetProps;
constructor(props: Props) {
super(props);
this._actionSheetRef = React.createRef();
}
getContext = () => {
return {
this._context = {
showActionSheetWithOptions: (options: ActionSheetOptions, callback: (i: number) => void) => {
this._actionSheetRef.current !== null &&
if (this._actionSheetRef.current != null) {
this._actionSheetRef.current.showActionSheetWithOptions(options, callback);
}
},
};
};
}
getContext(): ActionSheetProps {
return this._context;
}
render() {
return (
<Provider value={this.getContext()}>
<Provider value={this._context}>
<ActionSheet ref={this._actionSheetRef} useNativeDriver={this.props.useNativeDriver}>
{React.Children.only(this.props.children)}
</ActionSheet>