Project 77 of 100 - Local Notes in React with react-quill
Tags: react, javascript, 100daysofcode
Published: 2021-06-06 06:04:15

*Hey! I'm on a mission to make 100 React.js projects. Please follow my dev.to profile or my [twitter](https://www.twitter.com/jwhubert91) for updates and feel free to reach out if you have questions. Thanks for your support!*

Link to today's deployed app: [Link](https://100-react-projects-day-77-local-notes.netlify.app/)
Link to the repo: [github](https://github.com/jwhubert91/100daysofreact/tree/master/day-77-react-local-notes)

So I'm half-way through a [Youtube tutorial](https://www.youtube.com/watch?v=I250xdtUvy8&list=RDCMUC8butISFwT-Wl7EV0hUK0BQ&start_radio=1) about how to build an Evernote clone with React and Firebase when I realize (a) the video is really outdated with breaking code changes since it was released and (b) we are using a super cool npm package for React that I'd like to learn the modern way to implement. So I looked up the updated documentation, and learned how to do it the new-fashioned way.

The package is called [react-quill](https://www.npmjs.com/package/react-quill) and I had been looking for something like this for a while. It's a pre-built text editor component with styling and tons of customizability. [The documentation](https://github.com/zenoamaro/react-quill) shows the best way to install and include it in a create-react-app project:

```
npm install react-quill
```

then

```JS
import React, { useState } from "react";
import ReactQuill from 'react-quill';
import 'react-quill/dist/quill.snow.css';

function MyComponent() {
  const [value, setValue] = useState('');

  return (
    <ReactQuill theme="snow" value={value} onChange={setValue}/>
  );
}
```

It's as easy as that to have a nice code editor in your project! There are a ton of different built-in props and ways to extend it, so I didn't get to use everything, but I get a feel for how one could use it in larger projects and I implemented a way to use it with your browser's local storage, which is also quite useful.

Here was my configuration of the Quill component:

```JS
function App() {
  const [editorBody,setEditorBody] = useState('')

  ...

return (
...
  <main>
    <ReactQuill theme="snow" value={editorBody} onChange={setEditorBody} />
  </main>
)
```

Aside from that, all I do is use `useEffect` to load in past notes from storage when the component mounts. And I used some vanilla Javascript to save the note in local storage and the time in UTC format when the user closes the page. That way, anyone who uses this website will have their own local notes application they can bookmark.

Other resources used in this project:
1. [MDN docs on local storage](https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage)
2. ["Replacing React Lifecycle Methods with Hooks" (great article)](https://blog.bitsrc.io/replacing-react-lifecycle-methods-with-hooks-a-comprehensive-guide-dfd5cbe1f274)
3. [MDN docs on the window unload event](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onunload)
4. [This](https://stackoverflow.com/a/10211214/6179011) handy solution on converting a date string to a user's local time

**If you like projects like this and want to stay up to date with more, check out my Twitter [@jwhubert91](https://twitter.com/jwhubert91), I follow back! See you tomorrow for another project.**