Skip to content

Commit

Permalink
😍 useRef hook is used instead of direct DOM manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
aromalanil committed Sep 5, 2020
1 parent 06d2ebb commit 6543f09
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.6.3",
"version": "1.6.4",
"description": "A react app to preview and edit Markdown",
"private": true,
"author": {
Expand Down
6 changes: 4 additions & 2 deletions src/components/MarkdownEdit.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState,useRef } 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] = useState(false);
const editorRef =useRef(null);

useEffect(() => {
if(content===''){
Expand All @@ -22,7 +23,7 @@ function MarkdownEdit({ content, changeContent }) {

const handleClearButton = () => {
changeContent("");
document.getElementById("editor").focus();
editorRef.current.focus();
};

const handleCopyButton = () => {
Expand Down Expand Up @@ -52,6 +53,7 @@ function MarkdownEdit({ content, changeContent }) {
value={content}
onChange={handleEditorChange}
id="editor"
ref={editorRef}
></textarea>

<Snackbar open={open} autoHideDuration={2000} onClose={handleClose}>
Expand Down

0 comments on commit 6543f09

Please sign in to comment.