React-popper: use case for onCreate/onUpdate!

Created on 10 Jul 2017  路  3Comments  路  Source: popperjs/react-popper

i have a few cases where i'd like to "react" to some of the Popper data in my parent component (the one that renders <Popper>), but i currently have _no way_ to access this data safely. the only current option is to grab a ref to the Popper and inspect its state.data, but that doesn't feel reliable.

some sort of callback prop that would allow my parent component to receive the new Popper data would be very helpful. I wouldn't store all of it, i'd just look at the parts i need and update my minimal state.

(in particular, i'd like to have access to arrow offsets so i can modify my transform-origin)

Most helpful comment

well damn that seemed to work pretty well! i don't know what i was worried about with that approach... adding a modifier that calls setState based on data works 馃挴

probably reasonable to close this issue now

const updatePopoverState: Popper.ModifierFn = (data) => {
    // ... do computations based on data ...
    this.setState({ data, based, updates });
    return data;
}

All 3 comments

@souporserious just thought of a potential alternative: would it make sense to include data in the object given to the children functions, next to restProps?

Isn't a custom modifier enough to read data on each cycle?

well damn that seemed to work pretty well! i don't know what i was worried about with that approach... adding a modifier that calls setState based on data works 馃挴

probably reasonable to close this issue now

const updatePopoverState: Popper.ModifierFn = (data) => {
    // ... do computations based on data ...
    this.setState({ data, based, updates });
    return data;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gormonn picture gormonn  路  4Comments

alfnielsen picture alfnielsen  路  3Comments

craigsketchley picture craigsketchley  路  3Comments

rolandjitsu picture rolandjitsu  路  5Comments

linusthe3rd picture linusthe3rd  路  4Comments