Skip to main content

useInput

The useInput hook returns the InputDialogComponent component to render the InputDialog and openInputDialog function to open the InputDialogComponent programatically.

Importing the hook


import { useInput } from 'repopup';

Usage


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

const App = () => {
const { InputDialogComponent: InputDialog, openInputDialog } = useInput({
onSubmitCallback: (val: any) => console.log(val),
label: 'Name',
title: 'Your Name'
});
return (
<React.Fragment>
<Button onClick={() => openInputDialog()}>Open</Button>
<InputDialog type="text" placeholder="Enter your name..." />
</React.Fragment>
);
};

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


Function Signature


function useInput(
options: UseInputArgs,
): {InputDialogComponent:JSX.Element,openInputDialog: () => 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 input field