0.0.9 • Published 4 years ago

@foxsocial/framework v0.0.9

Weekly downloads
10
License
MIT
Repository
-
Last release
4 years ago

@foxsocial/framework

Shared Context

Shared context is a container contain common service likes i18n, apiClient, modal, layout, router It allow we to access it's service in sagas & general React Component.

Using shared context with i18n

import {useAppContext} from '@foxsocial/context'

function ComponentA(){
  
  // access i18n service in SharedContext.
  const {i18n: {t}} = useAppContext()
  return (<div>
            {t('say_hello')}
          </div>)
}

In saga context

import { getContext,call,put } from "redux-saga/effect"

export function * checkLoggedIn(){
  // using alert service instead of window.alert
  // using i18n.t from i18n next translation.
  // using apiClient from data.

  const { apiClient,i18n: {t}, alert} = yield getContext('sharedContext')
  yield call ((apiClient as any).post,'/path/to/api', {identity: 'email@domain.com', credential: 'password'})
  alert(t('say_hello'))
}