Before we move on to keyboard handling, let's refactor our Editor implementation a bit so that we can use React Hooks. We need do so this so that we can simplify how the code is handled significantly during load and save operations.
React Hooks is a relatively new feature, and if you have a background in React development, then you may have already heard of it or even used it.
Check out the official documentation on React Hooks to find out more: https://reactjs.org/docs/hooks-intro.html.
The most essential hook is the useState one. You are going to use it a lot in your projects. Let's import and use the useState hook so that we can provide a pair of getters and setters for the code text:
- Import the useState hook from the react namespace:
import React, { useState } from 'react';
- Replace the code variable initializer...