10 examples of 'react hook form npm' in JavaScript

Every line of 'react hook form npm' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
217function useHook(name: string, callback: (hook: Hook) => void, deps?: any[] | undefined): Hook {
218 const hooks = getHooksContextOrThrow();
219 if (hooks.currentPhase === 'MOUNT') {
220 if (deps != null && !Array.isArray(deps)) {
221 logger.warn(
222 `${name} received a final argument that is not an array (instead, received ${deps}). When specified, the final argument must be an array.`
223 );
224 }
225 const hook: Hook = { name, deps };
226 hooks.currentHooks.push(hook);
227 callback(hook);
228 return hook;
229 }
230
231 if (hooks.currentPhase === 'UPDATE') {
232 const hook = hooks.getNextHook();
233 if (hook == null) {
234 throw new Error('Rendered more hooks than during the previous render.');
235 }
236
237 if (hook.name !== name) {
238 logger.warn(
239 `Storybook has detected a change in the order of Hooks${
240 hooks.currentDecoratorName ? ` called by ${hooks.currentDecoratorName}` : ''
241 }. This will lead to bugs and errors if not fixed.`
242 );
243 }
244
245 if (deps != null && hook.deps == null) {
246 logger.warn(
247 `${name} received a final argument during this render, but not during the previous render. Even though the final argument is optional, its type cannot change between renders.`
248 );
249 }
250
251 if (deps != null && hook.deps != null && deps.length !== hook.deps.length) {
252 logger.warn(`The final argument passed to ${name} changed size between renders. The order and size of this array must remain constant.
253Previous: ${hook.deps}
254Incoming: ${deps}`);
255 }
256
257 if (deps == null || hook.deps == null || !areDepsEqual(deps, hook.deps)) {
258 callback(hook);
259 hook.deps = deps;
260 }
261 return hook;
262 }
263
264 throw invalidHooksError();
265}
Important

Use secure code every time

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

174export function prepareForReact() {
175 const needReact = !isModuleInstalled("react");
176 const needReactDom = !isModuleInstalled("react-dom");
177
178 if (needReact || needReactDom) {
179 print(devServerReactRequired());
180 }
181
182 needReact && installModule("react");
183 needReactDom && installModule("react-dom");
184}
16function hook(name, hook) {
17 if (SystemJSLoader.prototype[name])
18 SystemJSLoader.prototype[name] = hook(SystemJSLoader.prototype[name]);
19}
34_runHook(hook) {
35 return this._executionThread.run(Object.create(hook));
36}
27function reactPre(deps, defaults) {
28 return Object.keys(components).reduce(function (libs, x) {
29 return _extends({}, libs, _defineProperty({}, applyCapitalization(x), components[x](deps, defaults)));
30 }, {});
31}
114function installHook(name) {
115 const hookPath = path.join(hooksDir, name);
116
117 if (fs.existsSync(hookPath)) {
118 console.error(`△ @zeit/git-hooks: hook '${name}' already exists; skipping: ${hookPath}`);
119 return;
120 }
121
122 fs.symlinkSync('./_do_hook', hookPath);
123}
23function prepareHook(id) {
24
25 var hookPrototype = hooks[id];
26
27 // Allow disabling of hooks by setting them to "false"
28 if (hookPrototype === false || hooks[id.split('.')[0]] === false) {
29 delete hooks[id];
30 return;
31 }
32
33 // Check for invalid hook config
34 if (hooks.userconfig && !hooks.moduleloader) {
35 return cb('Invalid configuration:: Cannot use the `userconfig` hook w/o the `moduleloader` hook enabled!');
36 }
37
38 // Handle folder-defined modules (default to index.js)
39 // Since a hook definition must be a function
40 if (_.isObject(hookPrototype) && !_.isArray(hookPrototype) && !_.isFunction(hookPrototype)) {
41 hookPrototype = hookPrototype.index;
42 }
43
44 if (!_.isFunction(hookPrototype)) {
45 sails.log.error('Malformed hook! (' + id + ')');
46 sails.log.error('Hooks should be a function with one argument (`sails`)');
47 process.exit(1);
48 }
49
50 // Instantiate the hook
51 var def = hookPrototype(sails);
52
53 // Mix in an `identity` property to hook definition
54 def.identity = id.toLowerCase();
55
56 // If a config key was defined for this hook when it was loaded,
57 // (probably because a user is overridding the default config key)
58 // set it on the hook definition
59 def.configKey = hookPrototype.configKey || def.identity;
60
61 // New up an actual Hook instance
62 hooks[id] = new Hook(def);
63
64}
92async applyHook(key, opts = {}) {
93 const hooks = this.eventHooks[key] || [];
94 const results = [];
95 hooks.forEach((fn) => {
96 try {
97 results.push(fn(opts));
98 } catch (e) {
99 log.error(e);
100 log.error(`Fail to excute hook ${key}`);
101 }
102 });
103 await Promise.all(results);
104}
14export function requireHook(hook) {
15 requireHooks.push(hook)
16}
69async callHook (name, ...args) {
70 let fns = this.options.hooks[name]
71
72 if (!fns) {
73 return
74 }
75
76 if (!Array.isArray(fns)) {
77 fns = [fns]
78 }
79
80 for (const fn of fns) {
81 await fn(this, ...args)
82 }
83}

Related snippets