informed
Version:
A lightweight framework and utility for building powerful forms in React applications
34 lines (27 loc) • 658 B
JavaScript
import { useContext } from 'react';
import { ScopeContext } from '../Context.js';
/* ----------------------- useScope ----------------------- */
function useScope(name) {
var scope = useContext(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;
}
export { useScope };