Giter Club home page Giter Club logo

react-autosave's Introduction

Hey, I'm Jeremiah Tabb

I am a programmer interested in building scalable web and mobile apps, blazingly fast development tooling, and open source software projects. I also climb rocks, blog, and occasionally compose music.

Languages / Tools

Python Rust Golang Typescript Elixir Lua React Svelte Bash Docker Git NeoVim

react-autosave's People

Contributors

jollyjerr avatar limegrass avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-autosave's Issues

Doesn't save state to db quickly before creating new item?

Hey this is an amazing library but I do have an issue that I'm currently facing.

I have a simple app like this:

Docs App

I click on New Docs, type in quickly something & then click on New Docs again before it saves.

There is an indicator beside it that shows Saving & Saved state. When it's on Saving state & I switch to New Docs, it keeps the old doc empty because the state hadn't been saved.

See the new image below:

Screenshot 2021-12-28 at 4 43 58 PM

I did type in something quickly but clicked on New Docs immediately so it kept that part empty. 1st & 2nd item has Empty Docs in it (see image)

How do I fix it?

I have a full repro at https://github.com/deadcoder0904/docs-autosync/tree/react-autosave (see 2 files: DocsList.tsx & Writer.tsx)

Also, I'm wondering if alertIfUnsavedChanges is good to implement. https://github.com/lukesmurray/react-query-autosync has a similar option (search for alertIfUnsavedChanges on the readme) & here's the implementation

But would love to know if this is a problem with my implementation of react-autosave or not using React State perfectly or something else?

Could not find a declaration file for module 'react-autosave'

I imagine this is due to the fact that the types field in package.json is no longer used if there is an exports field

We'd need to move them inside the exports:

"exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/react-autosave.js",
      "require": "./dist/react-autosave.umd.cjs"
    }
  },

Unable to mock useAutosave hook since 0.4.0

Just installed the 0.4.0 update (thanks for the quick update) and the useAutosave hook mock (jest-mock) I was using in my tests stopped working.

It fails with the error Failed to get mock metadata: [...]/node_modules/react-autosave/dist/react-autosave.umd.js.

I’m no test guru, so I don’t have a fix to suggest, but I continue trying to find a workaround on my end.

Package not building

package does not work in production. Please deprecate or close till beta is over.

Passing `id` to `useCallback`?

Hey, thanks for this library. It's wonderfully simple. I was using use-react-query-auto-sync but it wasn't working for my usecase & this one did work removing a lot of code.

I am facing 1 problem though. In the README, it's mentioned I should use useCallback but I'm not sure how to pass id to it as I need that in the mutation.

id & text is everchanging in my case.

const updateDraft = useCallback(
    (newText: string) => {
      console.log('updateDraft')
      console.log({ id: snap.doc.id, text: newText })
      updateDocs({ id: snap.doc.id, text: newText })
      toggleIsSaved(true)
    },
    [snap.doc.id]
  )

  useAutosave({
    data: snap.doc.text,
    onSave: updateDraft,
  })

I am using valtio as a global state manager. That's where the snap.doc.id is coming from. But every time, the 1st snap.doc.id gets passed because of useCallback as the same function is used so every time it mutates the same row as snap.doc.id stays the same.

I'd love to know a solution to this.

Complete reproduction on branch react-autosavehttps://github.com/deadcoder0904/docs-autosync/tree/react-autosave

Support of objects and arrays for useDebounce.

HI!) When I used our hooks I Faced with a problem.
Currently, if you pass an object/array as data in useAutosave or useDebounce.
Then debouncing never stop.
I see the following solution.
But maybe you know how to implement it better, still I don't have much experience.
image

(node:6111) [DEP0128] DeprecationWarning: Invalid 'main' field in '~/docs-autosync/node_modules/react-autosave/package.json' of 'build/index.js'. Please either fix that or report it to the module author (Use `node --trace-deprecation ...` to show where the warning was created)

hey, i get a warning when in my console that says:

(node:6111) [DEP0128] DeprecationWarning: Invalid 'main' field in '~/docs-autosync/node_modules/react-autosave/package.json' of 'build/index.js'. Please either fix that or report it to the module author (Use node --trace-deprecation ... to show where the warning was created)

might wanna fix that :)

onSave not triggered if value evaluate to false

In the useAutosave.tsx, when evaluating if onSave will be called, if the value is falsy (empty string, 0), onSave is not called.

    if (initialRender.current) {
      initialRender.current = false;
    } else if (debouncedValueToSave) {
      onSave(debouncedValueToSave);
    }

You should remove this check.

P.S. thanks for this great hook!

package.json exports incorrect

package.json contains

  "module": "./dist/react-autosave.es.js",
  "exports": {
    ".": {
      "import": "./dist/react-autosave.es.js",
    }
  },

But dist/react-autosave.es.js does not exist. Looks like it should be dist/react-autosave.mjs instead.

onSave is called if onSave changes. Can this be optional?

My onSave callback needs to verify against a state value that changes often. But if I put that state value as a dependency to the useCallback, it will create a new callback each time that state value changes and then useAutosave will call onSave. I would like to silently update onSave without triggering useAutosave to call it.

componentWillUnmount fired

Hi, this lib is amazing. I have a question, how autosave behaves when componentWillUnmount fired before debounce time end?
If the user quickly fill a input and switches to another screen by menu, autosave should force save. I tried but to no avail.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.