Skip to content

Commit

Permalink
🍪 Caches the user input markdown to localstorage
Browse files Browse the repository at this point in the history
  • Loading branch information
aromalanil committed Apr 26, 2020
1 parent c91371a commit b504d16
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "markdown-editor",
"version": "1.3.1",
"version": "1.4.0",
"description": "A react app to preview and edit Markdown",
"private": true,
"author": {
Expand Down
14 changes: 12 additions & 2 deletions src/components/MarkdownEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import React from "react";
import React, { useEffect, useState } from "react";
import Snackbar from "@material-ui/core/Snackbar";
import { Alert, AlertTitle } from "@material-ui/lab";
import placeholder from "../data/placeholder";

function MarkdownEdit({ content, changeContent }) {
const [open, setOpen] = React.useState(false);
const [open, setOpen] = useState(false);

useEffect(() => {
if(content===''){
localStorage.setItem("markdown",placeholder);
}
else{
localStorage.setItem("markdown",content);
}
}, [content])

const handleEditorChange = (event) => {
event.preventDefault();
Expand Down
5 changes: 3 additions & 2 deletions src/components/WorkArea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React, { useState, useEffect } from "react";
import Split from "react-split";
import MarkdownEdit from "./MarkdownEdit";
import MarkdownPreview from "./MarkdownPreview";
import placeholder from '../data/placeholder'
import placeholder from "../data/placeholder";

function WorkArea() {
const [markDown, setMarkDown] = useState(placeholder);
let markdown = localStorage.getItem("markdown") || placeholder;
const [markDown, setMarkDown] = useState(markdown);
const [orientation, setOrientation] = useState("horizontal");

useEffect(() => {
Expand Down

0 comments on commit b504d16

Please sign in to comment.