Closed WhoAteDaCake closed 4 years ago
I guess this is more of a kapsule
question. My current approach was to add
useImperativeHandle(ref, () => {
return {
getCore() {
return comp;
},
};
});
And doing ref.current.getCore().focusOnNode(entry)
from the onClick
handler
@WhoAteDaCake you don't have to go so far. If you register the react kapsule with a list of methods:
const Chart = fromKapsule(chartKapsule, {
methodNames: ['focusOnNode']
})
the wrapper will do the useImperativeHandle
work for you and expose the method, accessible like so:
ref.current.focusOnNode(...)
Then you can add that to the onClick
handler if you wish.
Is there a way we have a function
onClick
on a component, without actually overriding logic of the component?Example : codesandbox. Here we add onClick, but that removes the zoom functionality of the chart