UNPKG

informed

Version:

A lightweight framework and utility for building powerful forms in React applications

38 lines (29 loc) 747 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var React = require('react'); var Context = require('../Context.js'); /* ----------------------- useScope ----------------------- */ function useScope(name) { var scope = React.useContext(Context.ScopeContext); // Example // scope = "friends[0]" // name = "friends[0]" // return "friends[0]" if (scope === name) { return name; } // Example // scope = "friends[0]" // name = "name" // return "friends[0].name" if (scope && name) { return "".concat(scope, ".").concat(name); } // Return what was passed if (name) { return name; } // If nothing passed reuturn the scope return scope; } exports.useScope = useScope;