@schibstedspain/sui-react-hooks
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -5,1 +5,11 @@ # Change Log | ||
<a name="1.2.0"></a> | ||
# 1.2.0 (2019-06-25) | ||
### Features | ||
* adaptation to be able to execute asynchronous functions ([70b94a1](https://github.com/SUI-Components/schibsted-spain-components/commit/70b94a1)) | ||
import { useEffect } from 'react'; | ||
export default function useMount(effect) { | ||
useEffect(effect, []); // eslint-disable-line | ||
useEffect(function () { | ||
return effect(); | ||
}, []); // eslint-disable-line | ||
} |
@@ -0,1 +1,2 @@ | ||
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import { useEffect, useRef, useState } from 'react'; | ||
@@ -23,4 +24,5 @@ import PropTypes from 'prop-types'; | ||
var _useState = useState(false), | ||
isIntersecting = _useState[0], | ||
setIntersecting = _useState[1]; | ||
_useState2 = _slicedToArray(_useState, 2), | ||
isIntersecting = _useState2[0], | ||
setIntersecting = _useState2[1]; | ||
@@ -38,3 +40,5 @@ var outerRef = useRef(); | ||
observer = new window.IntersectionObserver(function (_ref4) { | ||
var entry = _ref4[0]; | ||
var _ref5 = _slicedToArray(_ref4, 1), | ||
entry = _ref5[0]; | ||
// Update our state when observer callback fires | ||
@@ -41,0 +45,0 @@ setIntersecting(entry.isIntersecting); |
{ | ||
"name": "@schibstedspain/sui-react-hooks", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -31,3 +31,10 @@ # ReactHooks | ||
return <h1>Hey!</h1> | ||
const [currentUser, setCurrentUser] = useState(null) | ||
useMount(async () => { | ||
const user = await getUser() | ||
setCurrentUser(user) | ||
}) | ||
return currentUser && <h1>Hello {currentUser.name} !!</h1> | ||
} | ||
@@ -34,0 +41,0 @@ ``` |
5593
66
83