New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-simple-fetch-hoc

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-simple-fetch-hoc

React Fetch HOC ================= [![npm version](https://badge.fury.io/js/react-fetch-hoc.svg)](https://badge.fury.io/js/react-fetch-hoc)

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

React Fetch HOC

npm version

An experiment to quickly integrate and use an API requests with High Order Component 🚴🏽

The API might change any day.
Do not use in Production!

What is it ?

It's a simple library build on React High Order Components and on fetch (currently) which assumes responsibility for receiving data from the server and transferring it to your component.

Example

import React from 'react';
import fetch from 'isomorphic-fetch';
import fetchHoc from 'react-fetch-hoc';

const API_ROUTE = 'https://jsonplaceholder.typicode.com/posts';

const Post = ({ title, body }) => {
  return (
    <div>
      <h3>{title}</h3>
      <div>{body}</div>
    </div>
  )
}

const withFetchPost = fetchHoc(props => fetch(`${API_ROUTE}${props.id}`));
const PostContainer = withFetchPost(Post);

const App = ({ id = 1 }) => <PostContainer id={id} />
export default App;

The API get call to https://jsonplaceholder.typicode.com/posts/1 will send us response as

{
  title: 'Summer',
  body: 'That summer was so fine that I dec...'
}

What problem does it solve ?

Basically everyone is familiar with using fetch/axios in the componentDidMount method. This solution is not the cleanest of all. The concept built into this library allows us keep our components clean and just re-use them where necessary, changing only the shell.

FAQ ?

Feature Requests/Find Bug ?

If you see the potential in this library let's talk. Search for existing GitHub issues and join the conversation or create new!

Can I use this in production?

I wouldn't. Many use cases are not be considered yet. If you find some use cases this lib can't handle yet, please file an issue.

FAQs

Package last updated on 26 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc