New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-saga

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-saga

declarative saga management with jsx

latest
Source
npmnpm
Version
0.3.1
Version published
Weekly downloads
379
56.61%
Maintainers
1
Weekly downloads
 
Created
Source

react-saga Build Status Coverage Status

react-saga is an attempt to make data / logic dependencies declarative in the same way as UI. following code manages 3 sagas (AuthenticatedApi, AnotherAuthenticatedSaga, GuestApi) based on authentication state and current user id. react-saga forks / cancels sagas based on their presence in render tree and passed props. in this case AnotherAuthenticatedSaga is running when user is authenticated, AuthenticatedApi is running when authenticated as well, but restarts on userId changes.

import React from 'react';
import { put } from 'redux-saga/effects';
import { reactSaga, Group } from 'react-saga';

function *AuthenticatedApi({ userId }) {
  yield put({ type: 'USER_ID_CHANGED', userId });
  while (true) {
    // handle authenticated api calls
  }
}

function *AnotherAuthenticatedSaga() {
  // whatever
}

function *GuestApi() {
  while (true) {
    // handle guest api calls
  }
}

function Api({ state: { authenticated, userId } }) {
  if (authenticated) {
    return (
      <Group>
        <AuthenticatedApi userId={userId}/>
        <AnotherAuthenticatedSaga/>
      </Group>
    );
  }
  return <GuestApi/>;
}

export default reactSaga(<Api/>);

FAQs

Package last updated on 09 Apr 2019

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