Closed HimorriveL closed 3 years ago
Hey @HimorriveL, I didn't understand what u are trying to do, can you provide us some code so we can take a deeper look on what's happening?
Hi diego3g, yesterday I finally resolve this problem
on bridge.ts:
const events:any ={};
export const api = {
on1(event:any, handler:any) {
events[event] = handler;
},
send1(event:any, data:any) {
events[event](event, data);
},
removeAllListeners1(event:any) {
events[event] = undefined;
},
}
on Greetings/index.tsx
const [listingsCount, setListingsCount] = useState(0);
useEffect(() => {
window.Main.on1('count-listings', (event:any, count:any) => {
setListingsCount(count);
});
window.Main.send1('count-listings', 2);
return function cleanup() {
window.Main.removeAllListeners1('count-listings');
};
}, []);
const handleSayHello = useCallback(async () => {
window.Main.send1('count-listings', 666);
}, []);
return (
<Container>
<Image
src="https://www.vectorlogo.zone/logos/reactjs/reactjs-icon.svg"
alt="ReactJS logo"
/>
<Text>An Electron boilerplate including TypeScript, React, Jest and ESLint.</Text>
<Button onClick={handleSayHello}>Send message to main process</Button>
<div>{listingsCount}</div>
</Container>
)
};
how can I get message value to set on react page?, I really tried a lot things, without success