mirror of
https://github.com/AykutSarac/jsoncrack.com.git
synced 2025-01-27 15:22:56 +08:00
fix initial data
This commit is contained in:
parent
9802e88838
commit
bce08c99b2
@ -57,15 +57,12 @@ export const JsonEditor: React.FC<{
|
||||
json: string;
|
||||
setJson: React.Dispatch<React.SetStateAction<string>>;
|
||||
}> = ({ json, setJson }) => {
|
||||
const [initialJson, setInitialJson] = React.useState(
|
||||
React.useMemo(
|
||||
() =>
|
||||
typeof localStorage !== "undefined" && localStorage.getItem("json")
|
||||
? localStorage.getItem("json")
|
||||
: json,
|
||||
[]
|
||||
)
|
||||
);
|
||||
const [initialJson, setInitialJson] = React.useState(json);
|
||||
|
||||
React.useEffect(() => {
|
||||
const jsonStored = localStorage.getItem("json");
|
||||
if (jsonStored) setInitialJson(jsonStored);
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (json === "[]") setInitialJson(json);
|
||||
|
Loading…
x
Reference in New Issue
Block a user