Skip to main content

useSelect

The useSelect hook returns the SelectComponent component to render the Select and openSelectDialog function to open the SelectComponent programatically.

Importing the hook


import { useSelect } from 'repopup';

Usage


import React from 'react';
import { useSelect , RepopupProvider } from 'repopup';
import ReactDOM from 'react-dom';


const inputOptions = {
Sports:
{
football: 'Foolball',
cricket: 'Cricket',
badminton: 'Badminton',
basketball: 'Basketball'
},
Players:
{
messi: 'Messi',
ronaldo: 'Ronaldo',
lewandowski: 'Lewandowski'
},
ucl: 'Champions League'
};

const App = () => {
const { SelectComponent: SelectDialog, openSelectDialog } = useSelect({
onSubmitCallback: (val: any) => console.log(val),
inputOptions,
label: 'Football Mania'
});
return (
<React.Fragment>
<Button onClick={() => openSelectDialog()}>Open</Button>
<SelectDialog placeholder="Choose your option" />
</React.Fragment>
);
};

ReactDOM.render(
<RepopupProvider>
<App />
</RepopupProvider>,
,document.querySelector('#app'));

tip

Now , here to understand how can we pass the inputOptions to our useSelect hook, ypu can visit here , where it has been explained in detail.

Function Signature


function useSelect(
options: UseSelectArgs,
): {SelectComponent:JSX.Element,openSelectDialog: () => void}


Options

OptionTypeDescriptionDefault
closeOnBackdropClickbooleanWheather or not to close the popup on clicking the backdroptrue
titlestringUsed for the title of the popup
cancelButtonTextstringUse this to change the text on the "Cancel"-button.'Cancel'
onSubmitCallback(value: any) => void;Function that will be run when the "Submit"-button is clicked
submitButtonTextstringUse this to change the text on the "Submit"-button.'Submit'
labelstringUsed to give a label to the select field
inputOptionsInputOptionsTypeoptions for the Select dailog component{}