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
When prop needs to be of object/array type, it needs to be operated through JS. However, the rendering of custom-element in React Hook does not seem to be consistent with the execution logic of useEffect after component rendering. The phenomenon is that the effect function is executed earlier than the custom-element, causing the setting prop to not work correctly
It cannot be reproduced in CodeSendbox, but it is not normal locally. React version is consistent
importReact,{useState,useEffect}from"react";importReactDOMfrom"react-dom";import"./styles.css";functionApp(){const[stringProp,setStringProp]=useState("stringProp");const[booleanProp,setBooleanProp]=useState(true);const[numberProp,setNumberProp]=useState(1);useEffect(()=>{// this is work in my local// setTimeout(() => {// document.getElementsByTagName("table-wc")[0].items = [// { prop: "1", value: "1", type: "1" },// { prop: "2", value: "2", type: "2" }// ];// }, 1000);// Not work in my local. I guess effect function was executed before table-wc created,// which caused the items to not be set upconsole.log(1111111);document.getElementsByTagName("table-wc")[0].items=[{prop: "1",value: "1",type: "1"},{prop: "2",value: "2",type: "2"}];});return(<divclassName="App"><table-wcstring-prop={stringProp}boolean-prop={booleanProp}number-prop={numberProp}></table-wc></div>);}constrootElement=document.getElementById("root");ReactDOM.render(<App/>,rootElement);
Local:
Expected
The text was updated successfully, but these errors were encountered:
my9074
changed the title
【React】vue-custom-element set Object/Array prop in React Hook, the operation result is unstable
【React】custom-element set Object/Array prop in React Hook, the operation result is unstable
Apr 25, 2021
@karol-f
When prop needs to be of object/array type, it needs to be operated through JS. However, the rendering of custom-element in React Hook does not seem to be consistent with the execution logic of useEffect after component rendering. The phenomenon is that the effect function is executed earlier than the custom-element, causing the setting prop to not work correctly
CodeSendbox demo
Local:
Expected
The text was updated successfully, but these errors were encountered: