Giter Site home page Giter Site logo

React Native database? about freactal HOT 2 CLOSED

stovmascript avatar stovmascript commented on June 10, 2024
React Native database?

from freactal.

Comments (2)

bingomanatee avatar bingomanatee commented on June 10, 2024

keep in mind this code was from before I noticed the initialize method but: I have a list of key state parameters that I serialize to the session state object in the browser and/or pull from an API:

    middleware: [
      (context) => { // save select values into session
        console.log('context state = ', context.state);
        if (sessionStorage && context.state) {
          if (!context.state.backgrounds) {
            console.log('no backgrounds');
          }
          for (let def of LOAD_STATES) {
            if (!def.loadFromAPI) {
              putInSession(def.name, context.state[def.name] || null, def.type);
            }
          }
        }
        return context;
      } ,
      (context) => { // load values from API
        for (let def of LOAD_STATES) {
          if (def.loadFromAPI && (!def.loadStart)) {
              def.loadStart = true;
              axios.get(`${config.API_ROOT}choices/${def.name}`)
                .then((result) => {
                let value = result.data;
                context.effects.fromAPI(def.name, value);
                def.loadDone = true;
            });
            }
            //putInSession(def.name, context.state[def.name] || null, def.type);
          }
        return context;
      }
    ]

from freactal.

divmain avatar divmain commented on June 10, 2024

initialState would definitely be a natural place to do this. The docs call out SSR scenarios as the prime example, but it is really intended for any case where you need to set state when the stateful component is originally loaded. In the case of an app-wrapper, it would make sense to pull in saved state there.

hydrate does some special work to match server-rendered components with their locally-rendered stateful counterparts. You shouldn't need to use it here.

Sorry for very delayed reply, but hope you were able to work things out. Going to close this as resolved, but please do feel free to re-open if you'd like additional help.

from freactal.

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.