'How do we can save the effect of last action in React.js and Fabric.js
These are states
const {activeCanvas, activeObject} = useContext(CanvasStore)
const [strokeWidth,setStrokeWidth]=useState(0)
const [color,setColor]=useState("black")
const [colorValue,setColorValue] =useState("white")
UseEffect() hook
useEffect(()=>{
if(activeObject?.subType === "Image"){
setStrokeWidth(activeObject.strokeWidth)
setColor(activeObject.color)
setColorValue(activeObject.color)
}
},[])
These are the functions, of those I want to maintain the result before next occurrence without rendering
Solution 1:[1]
Actually, the issue that I faced is related to the condition (if) in useEffect hook. So, while writing that name it properly. Don't make hurry but look carefully the name of the field in object
useEffect(()=>{
if(activeObject?.custom.subType === "Image"){
setStrokeWidth(activeObject.strokeWidth)
setColor(activeObject.color)
setColorValue(activeObject.stroke)
}
},[])
const borderColor=(color)=>{
setColorValue(color)
console.log(activeObject)
if(activeObject?.custom.subType === "Image"){
activeObject.set({stroke:color});
activeCanvas.renderAll();
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ali |
