保存到移动设备上的本地存储中[反应]

时间:2020-04-16 09:00:47

标签: javascript reactjs react-hooks

我有一个简单的笔记应用程序,可以保存到本地存储中。使用React构建。在桌面上运行正常。

但是,如果我在移动设备上访问网站,则不会保存到本地存储中。为此,我需要知道些什么。

代码如下

export default function App() {
  const localNotes = localStorage.getItem("notes");
  const [notes, setNotes] = useState(localNotes);

  const handleChange = e => {
    localStorage.setItem("notes", e.target.value);
    setNotes(e.target.value);
  };

  return (
    <form>
      <label for="pad">
        <span>Add your notes</span>
        <textarea
          rows="10"
          placeholder="Add notes here ?"
          name="pad"
          value={notes}
          onChange={handleChange}
        />
      </label>
    </form>
  );
}

1 个答案:

答案 0 :(得分:0)

要能够在您需要访问的设备上进行写操作,您用来保存的功能可以完美地在台式机上运行,​​而在设备,Android或iOS上完全可以运行。你应该看一下。