MCPcopy Create free account
hub / github.com/WebReflection/neverland / useState

Function useState

test/neverland.js:365–389  ·  view source on GitHub ↗
(value, options)

Source from the content-addressed store, hash-verified

363 always: false
364 };
365 var useState = function useState(value, options) {
366 var state = current();
367 var i = state.i++;
368 var hook = state.hook,
369 args = state.args,
370 stack = state.stack;
371
372 var _ref = options || defaults,
373 sync = _ref.sync,
374 always = _ref.always;
375
376 if (stack.length <= i) {
377 stack[i] = isFunction(value) ? value() : value;
378 if (!updates.has(hook)) updates.set(hook, sync ? update : reraf());
379 }
380
381 return [stack[i], function (value) {
382 var newValue = isFunction(value) ? value(stack[i]) : value;
383
384 if (always || stack[i] !== newValue) {
385 stack[i] = newValue;
386 updates.get(hook)(hook, null, args);
387 }
388 }];
389 };
390
391 /*! (c) Andrea Giammarchi - ISC */
392 var hooks = new WeakMap();

Callers 2

test.jsFile · 0.70
useReducerFunction · 0.70

Calls 3

currentFunction · 0.85
isFunctionFunction · 0.85
rerafFunction · 0.70

Tested by

no test coverage detected