I don't have any experience with CKEditor, but it probably does not take changes to the config
prop into account, which would explain the stale values. You could use useRef
(docs) to get rentTableRenderer
to use the current value of rentTableData
.
Just add a new constant rentTableDataRef
and replace rentTableData
in the body of the arrow function with rentTableData.current
:
export const LeaseEditor = ({ onChange, leaseDocument, save, rentTableData }: any) => {
// rentTableData is the prop that will change
console.log(rentTableData) // this shows the correct values when the prop changes
const rentTableDataRef = useRef(rentTableData)
const config = {
...
rentTable: {
rentTableRenderer: (domElement: any) => {
console.log('rentTableData in method', rentTableDataRef.current)
ReactDOM.render(<RentTablePreview values={rentTableDataRef.current} />, domElement)
},
},
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…