You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does Postmate.Model's options can monitor but cant change data in react?
My need is to monitor the data sent by the parent page in the subpage(iframe), and display the data on the subpage after receiving.
The childAPI in Postmate.Model().then() does not have an "on" function like new Postmate().then(), so I put the eventListener-"count" in options, when I get the data and use setState to change it, data can be changed, but the dom does not render this data .
T-T。
Am I use the wrong way?
// iframe export default function View() { const [countFromParent, setCountFromParent] = useState(0); useEffect(() => { new Postmate.Model({ count: (data) => { console.log("received:", data) // data has received setCountFromParent(data); } }); }, []) console.log("countFromParent:", countFromParent) // countFromParent has changed return ( // but there's actually no rendering <h1> {countFromParent }</h1> ); }
The text was updated successfully, but these errors were encountered:
It's not about react. This is because the iframe configured in the parent page is automatically generated instead of using an existing iframe.So no changes will be made to the iframe already on the page.
I have encountered a scenario that can reproduce this situation:
constCONTAINER_ID='container_id'newPostmate({container: document.getElementById(CONTAINER_ID),url:'xxx',name: 'xxx',});// ❌ Actually, it's not necessary to use the<iframe>tagconstParentPage=()=>{return(<div><iframeid={CONTAINER_ID}></iframe></div>)}// ✅constParentPage=()=>{return<divid={CONTAINER_ID}></div>}
Does Postmate.Model's options can monitor but cant change data in react?
My need is to monitor the data sent by the parent page in the subpage(iframe), and display the data on the subpage after receiving.
The childAPI in Postmate.Model().then() does not have an "on" function like new Postmate().then(), so I put the eventListener-"count" in options, when I get the data and use setState to change it, data can be changed, but the dom does not render this data .
T-T。
Am I use the wrong way?
// iframe
export default function View() {
const [countFromParent, setCountFromParent] = useState(0);
useEffect(() => {
new Postmate.Model({
count: (data) => {
console.log("received:", data) // data has received
setCountFromParent(data);
}
});
}, [])
console.log("countFromParent:", countFromParent) // countFromParent has changed
return (
// but there's actually no rendering
<h1> {countFromParent }</h1>
);
}
The text was updated successfully, but these errors were encountered: