Git Product home page Git Product logo

Comments (5)

ryanbrainard avatar ryanbrainard commented on May 14, 2024

I like the idea in general, but I'd like to see how well it works with PromiseStates, especially ones that are composed with PromiseState.all() and need to be decomposed on fulfillment. We use that pattern heavily to block on groups of fetches that should rendered together. This might also make it easier to allow for application provided defaults for the pending and error states. If you'd like to try making a PromiseState-specific version of this, it would at least be interesting thought experiment.

from react-refetch.

hnordt avatar hnordt commented on May 14, 2024

I'll use React Refetch on my projects, then I'll start the experiments with "HOCing".

Soon I'll post my thoughts.

from react-refetch.

hnordt avatar hnordt commented on May 14, 2024

@ryanbrainard I found a simple solution, I don't even need to change my code:

import React from 'react';
import { connect, PromiseState } from 'react-refetch';
import Async from '@hnordt/reax-async';
import ProjectPanel from './ProjectPanel.js';

const AsyncProjectPanel = Async(ProjectPanel);

const Projects = ({
  projectsFetch,
  likesFetch
}) => {
  const allFetches = PromiseState.all([userFetch, likesFetch]);
  return (
    <AsyncProjectPanel
      projects={projectsFetch.value}
      likes={likesFetch.value}
      isLoading={allFetches.pending}
      error={allFetches.reason} />
  );
};

export default connect(() => ({
  projectsFetch: '/api/projects.json',
  likesFetch: '/api/likes.json'
}))(Projects);

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 14, 2024

It works, but I personally don't like having to see the attributes of the PromiseState in all my components and also has duplication for the pending and error states. I like the HOC, but it should really be PS-specific to be used with Refetch IMHO. Perhaps a second-order HOC could even handle the application-specific defaults so something could be included (mostly) out of the box.

from react-refetch.

ryanbrainard avatar ryanbrainard commented on May 14, 2024

I'm going to close this for now since there's nothing really actionable here at this point. If you'd like to provide an HOC PromiseStateContainer, please open a pull request. It could even just a link in the readme to a gist, but bonus points if it can be a double HOC the incorporated application defaults and can be included in this library.

from react-refetch.

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.