@iteam/hooks
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -502,4 +502,33 @@ 'use strict'; | ||
var useLocalStorage = function useLocalStorage(key, initialValue) { | ||
var _useState = react.useState(function () { | ||
try { | ||
if (initialValue) { | ||
return initialValue; | ||
} else { | ||
return localStorage.getItem(key) || ''; | ||
} | ||
} catch (_unused) { | ||
// Try/catch because the user might be in private mode | ||
// JSON.stringify might also throw | ||
return ''; | ||
} | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
value = _useState2[0], | ||
setValue = _useState2[1]; | ||
react.useEffect(function () { | ||
try { | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
} catch (_unused2) {// Try/catch because the user might be in private mode | ||
// JSON.stringify might also throw | ||
} | ||
}, [value]); | ||
return [value, setValue]; | ||
}; | ||
exports.useToggle = useToggle; | ||
exports.useQueryParam = useQueryParam; | ||
exports.useDebounce = useDebounce; | ||
exports.useLocalStorage = useLocalStorage; |
@@ -498,2 +498,30 @@ import { useState, useEffect } from 'react'; | ||
export { useToggle, useQueryParam, useDebounce }; | ||
var useLocalStorage = function useLocalStorage(key, initialValue) { | ||
var _useState = useState(function () { | ||
try { | ||
if (initialValue) { | ||
return initialValue; | ||
} else { | ||
return localStorage.getItem(key) || ''; | ||
} | ||
} catch (_unused) { | ||
// Try/catch because the user might be in private mode | ||
// JSON.stringify might also throw | ||
return ''; | ||
} | ||
}), | ||
_useState2 = _slicedToArray(_useState, 2), | ||
value = _useState2[0], | ||
setValue = _useState2[1]; | ||
useEffect(function () { | ||
try { | ||
localStorage.setItem(key, JSON.stringify(value)); | ||
} catch (_unused2) {// Try/catch because the user might be in private mode | ||
// JSON.stringify might also throw | ||
} | ||
}, [value]); | ||
return [value, setValue]; | ||
}; | ||
export { useToggle, useQueryParam, useDebounce, useLocalStorage }; |
export {}; |
export {}; |
export {}; |
export * from './useToggle'; | ||
export * from './useQueryParam'; | ||
export * from './useDebounce'; | ||
export * from './useLocalStorage'; |
export declare const useDebounce: <ValueType>(value: ValueType, delay: number) => ValueType; |
export declare const useLocalStorage: (key: string, initialValue?: any) => [string, (newValue: string) => void]; |
export declare const useQueryParam: (param: string) => string | string[]; |
export declare const useToggle: (initialValue: boolean) => [boolean, () => void]; |
@@ -10,2 +10,3 @@ module.exports = { | ||
}, | ||
setupFiles: ['jest-localstorage-mock'], | ||
setupFilesAfterEnv: [ | ||
@@ -12,0 +13,0 @@ 'jest-dom/extend-expect', |
{ | ||
"name": "@iteam/hooks", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"main": "dist/hooks.cjs.js", | ||
@@ -33,17 +33,18 @@ "module": "dist/hooks.esm.js", | ||
"@babel/preset-typescript": "7.1.0", | ||
"@types/jest": "23.3.13", | ||
"@types/jest": "24.0.0", | ||
"@types/query-string": "6.2.0", | ||
"@types/react": "16.7.22", | ||
"eslint": "5.12.1", | ||
"@types/react": "16.8.2", | ||
"eslint": "5.13.0", | ||
"husky": "1.3.1", | ||
"is-ci-cli": "1.1.1", | ||
"jest": "24.0.0", | ||
"jest-dom": "3.0.1", | ||
"jest": "24.1.0", | ||
"jest-dom": "3.0.2", | ||
"jest-environment-jsdom": "24.0.0", | ||
"jest-environment-jsdom-global": "1.1.0", | ||
"lint-staged": "8.1.1", | ||
"prettier": "1.16.3", | ||
"react": "16.8.0", | ||
"react-dom": "16.8.0", | ||
"react-testing-library": "5.4.4", | ||
"jest-localstorage-mock": "2.4.0", | ||
"lint-staged": "8.1.3", | ||
"prettier": "1.16.4", | ||
"react": "16.8.1", | ||
"react-dom": "16.8.1", | ||
"react-testing-library": "5.5.3", | ||
"rollup": "1.1.2", | ||
@@ -50,0 +51,0 @@ "rollup-plugin-babel": "4.3.2", |
# Iteam Hooks | ||
[![npm version](https://badge.fury.io/js/%40iteam%2Fhooks.svg)](https://badge.fury.io/js/%40iteam%2Fhooks) | ||
[![Build Status](https://travis-ci.com/Iteam1337/hooks.svg?branch=master)](https://travis-ci.com/Iteam1337/hooks) | ||
This is a collection of hooks that we can reuse for any project that needs them. It's also a source of use cases of [React Hooks](https://reactjs.org/docs/hooks-reference.html) and how to test them using [react-testing-library](https://github.com/kentcdodds/react-testing-library/). | ||
@@ -4,0 +7,0 @@ |
@@ -9,3 +9,3 @@ import commonjs from 'rollup-plugin-commonjs' | ||
export default { | ||
input: './src/index.tsx', | ||
input: './src/index.ts', | ||
@@ -12,0 +12,0 @@ external: ['react'], |
import 'jest-dom/extend-expect' |
@@ -0,0 +0,0 @@ import { useState, useEffect } from 'react' |
@@ -10,3 +10,3 @@ import { useState, useEffect } from 'react' | ||
if (initialValue) { | ||
return JSON.stringify(initialValue) | ||
return initialValue | ||
} else { | ||
@@ -13,0 +13,0 @@ return localStorage.getItem(key) || '' |
@@ -0,0 +0,0 @@ import { useState } from 'react' |
@@ -0,0 +0,0 @@ import { useState } from 'react' |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35602
37
1085
127
26