Giter Site home page Giter Site logo

Comments (4)

bholloway avatar bholloway commented on August 20, 2024 2

So for reference we are talking about flushSync in react.

Given the setState interface is already analogous to react then it's important to keep using react paradigms as much as possible. To avoid confusion and to take advantage of existing familiarity with react.

Having a function scope where the synchronous event occurs is useful in that arbitrary other operations can be located there be known to be synchronous.

In comparison the additional arguments on the setState() is less elegant IMO. Fails interface segregation principle adding a bunch more "options" to achieve what can be done by composition.

from react-sweet-state.

AlexThurston avatar AlexThurston commented on August 20, 2024

You can also see this behaviour with the advanced-scoped-flow in it's stock form while using the input component.

from react-sweet-state.

albertogasparin avatar albertogasparin commented on August 20, 2024

Ha, good catch, I've never known of this gotcha. It's related to facebook/react#955
React tracks the cursor position only for sync re-renders 😞 so, since we moved RSS updates to be scheduled by default (even if with a duration of just one tick), it loses the cursor position.
Quite tricky. Not sure how to handle this 🤔

from react-sweet-state.

albertogasparin avatar albertogasparin commented on August 20, 2024

What do you think about a flushSync API (similar to the react-dom v18 util) to force updates to be dispatched synchronously?

const actions = {
  setName:
    (name: string): Action<State> =>
    ({ setState }) => {
      flushSync(() => {
        setState({ name: name });
      });
    },
};

Or an alternative could be adding a second, optional argument to setState:

const actions = {
  setName:
    (name: string): Action<State> =>
    ({ setState }) => {
      setState({ name: name }, { sync: true });
    },
};

from react-sweet-state.

Related Issues (20)

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.