5
จะใช้ React.forwardRef ในองค์ประกอบตามคลาสได้อย่างไร
ฉันพยายามใช้ React.forwardRef แต่สะดุดวิธีทำให้มันทำงานในองค์ประกอบตามคลาส (ไม่ใช่ HOC) ตัวอย่างเอกสารใช้องค์ประกอบและส่วนประกอบที่ใช้งานได้แม้กระทั่งการตัดคลาสในฟังก์ชันสำหรับส่วนประกอบลำดับที่สูงกว่า เริ่มต้นด้วยสิ่งนี้ในref.jsไฟล์: const TextInput = React.forwardRef( (props, ref) => (<input type="text" placeholder="Hello World" ref={ref} />) ); และแทนที่จะกำหนดเป็นดังนี้: class TextInput extends React.Component { render() { let { props, ref } = React.forwardRef((props, ref) => ({ props, ref })); return <input type="text" placeholder="Hello World" ref={ref} />; } …
115
javascript
reactjs