swiftui-react-native
Version:
A React Native component library inspired by SwiftUI
22 lines • 780 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useBinding = void 0;
const react_1 = require("react");
/**
* Creates a Binding object that can be used to read and write to a value.
* Components can recieve a binding as a prop and can handle the logic of
* getting and setting the value from inside the component.
* @param initialValue
* @returns A Binding containing the value and a setter function.
*/
function useBinding(initialValue) {
const [value, setValue] = (0, react_1.useState)(initialValue);
const toggle = () => setValue(!value);
return {
value,
setValue,
...(typeof initialValue === 'boolean' && { toggle }),
};
}
exports.useBinding = useBinding;
//# sourceMappingURL=useBinding.js.map