Socket
Book a DemoInstallSign in
Socket

react-preserve

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-preserve

Component that can preserve given data using localStorage

latest
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

React Preserve

Preserves your data, and reduces the amount of unnecessary data fetching.

Basic example

This example is using a render prop, but Preserve also provides children as a function.

import React, { Component } from 'react';
import Preserve from 'react-preserve';

class App extends Component {
  render() {
    return (
      <Preserve
        storageHook={(item, storage) => {}}
        setInitialDataValue={[]}
        preserveAs={'posts'}
        fetchFrom={'https://jsonplaceholder.typicode.com/posts'}
        render={({ data, fetching, error }) => {
          return fetching ? (
            <p>Loading....</p> // Will only happen once.
          ) : (
            data.map(item => {
              return (
                <div>
                  <h2>{item.title}</h2>
                  <p>{item.body}</p>
                </div>
              );
            })
          );
        }}
      />
    );
  }
}

Keywords

react

FAQs

Package last updated on 29 Jan 2018

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