From e8d755c14a7d59899af4bb62f0da17330ed01293 Mon Sep 17 00:00:00 2001 From: sovetski Date: Sun, 21 May 2023 14:24:07 +0200 Subject: [PATCH] Update README.md New localStorage example --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index d4028ddb..672aa23b 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,33 @@ import { Resizable } from 're-resizable'; ``` +### Example with `localStorage` + +```javascript +import { useState, useEffect } from "react"; +import { Resizable } from 're-resizable'; + +export default function MyComponent() { + const [width, setWidth] = useState(localStorage.getItem("componentWidth") || 250); + + useEffect(() => { + localStorage.setItem("componentWidth", width); + }, [width]); + + return ( + { + setWidth(ref.offsetWidth); + }} + }} + > + Sample with size + + ); +} +``` + ## Props #### `defaultSize?: { width: (number | string), height: (number | string) };`