minutemailer / react-popup

React popup component
http://minutemailer.github.io/react-popup/
MIT License
208 stars 71 forks source link

Passing variables #29

Closed SkyJedi closed 7 years ago

SkyJedi commented 7 years ago

Is it possible to pass a variable to and from the popup. I've found a work around by setting a firebase varaible within the popup, but it would be super helpful to pass a variable

tbleckert commented 7 years ago

May I ask what you need it for? Or rather how you would use it so I can get an idea of it.

SkyJedi commented 7 years ago

simply I'd like to have a popup ask for confirmation on deleting data.

click a button---->popup "are you sure"---->do this function that involves setting state

tbleckert commented 7 years ago

Something like this?

class MyComponent extends React.Component {

    constructor(props) {
        super(props);

        this.state = {
            foo: 'bar'
        };
    }

    confirm() {
        Popup.create({
            title: 'Are you sure?',
            content: 'Everything will be lost forever',
            buttons: {
                left: ['cancel'],
                right: [{
                    text: 'Yes!',
                    action: () => {
                        this.setState({foo: 'baz'});
                    }
                }]
            }
        });
    }

    render() {
        return <button onClick={() => this.confirm()}>Click me</button>;
    }

}
SkyJedi commented 7 years ago

HOLY CRAP YES!

sorry, I'm not good at this

vTrip commented 7 years ago

@tbleckert - I was performing the same logic as you with no success.

My solution was, after looking close at your code, changing the action to take () => .. instead of function ().

Would you have any insight into why the latter worked (unless this feels like a mystery case).

Would love to understand more about why that changed actually worked.