haradakunihiko / react-confirm

Small library which makes your Dialog component callable.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accessing context when calling confirm function

Maadtin opened this issue · comments

Is there a way to access my app context from inside the ConfirmDialog from the example? it is returning an empty object when calling it :S

This is my Dialog

function ConfirmDialog(props) {
    const theme  = useTheme();
    const {
        show,
        proceed,
        confirmation,
        options
    } = props;
    return (
        <Modal onHide={() => proceed(false)} show={show}>
            <div>{JSON.stringify(theme)}</div>
        </Modal>
    );
}

And this is the helper function that im calling:

function confirmDialog(message, options = {}) {
    let confirm = createConfirmation(ConfirmDialog);
    return confirm({confirmation: message, options});
}

The problem is that when calling this confirmDialog function my ConfirmDialog component cannot access the theme context and its throwing an error.

Thanks in advance !

Hmm, I don't have any good solution about this. Since this library create another react tree, context can not be shared.