How to use the baobab.type function in baobab

To help you get started, we’ve selected a few baobab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yomguithereal / baobab-react / src / higher-order.js View on Github external
/**
 * Baobab-React Higher Order Component
 * ====================================
 *
 * ES6 state of the art higher order component.
 */
import React from 'react';
import Baobab from 'baobab';
import {curry, isBaobabTree, solveMapping} from './utils/helpers';
import PropTypes from './utils/prop-types';

const makeError = Baobab.helpers.makeError,
      isPlainObject = Baobab.type.object;

/**
 * Helpers
 */
function displayName(Component) {
  return Component.name || Component.displayName || 'Component';
}

function invalidMapping(name, mapping) {
  throw makeError(
    'baobab-react/higher-order.branch: given cursors mapping is invalid (check the "' + name + '" component).',
    {mapping}
  );
}

/**
github Yomguithereal / baobab-react / src / hooks.js View on Github external
import React, {useContext, useState, useEffect} from 'react';
import {isBaobabTree} from './utils/helpers';
import Baobab from 'baobab';
import BaobabContext from './context';

const makeError = Baobab.helpers.makeError,
      isPlainObject = Baobab.type.object;

function invalidMapping(name, mapping) {
  throw makeError(
    'baobab-react/hooks.useBranch: given cursors mapping is invalid (check the "' + name + '" component).',
    {mapping}
  );
}

export function useRoot(tree) {
  if (!isBaobabTree(tree))
    throw makeError(
      'baobab-react/hooks.useRoot: given tree is not a Baobab.',
      {target: tree}
    );

  const [state, setState] = useState(() => {

baobab

JavaScript persistent data tree with cursors.

MIT
Latest version published 3 years ago

Package Health Score

56 / 100
Full package analysis