@atlaskit/profilecard
Version:
A React component to display a card with user information.
56 lines • 2 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { useState } from 'react';
export var useProfileInfo = function useProfileInfo(_ref) {
var fetchUserProfile = _ref.fetchUserProfile;
var _useState = useState(false),
_useState2 = _slicedToArray(_useState, 2),
isLoading = _useState2[0],
setIsLoading = _useState2[1];
var _useState3 = useState(null),
_useState4 = _slicedToArray(_useState3, 2),
error = _useState4[0],
setError = _useState4[1];
var _useState5 = useState(),
_useState6 = _slicedToArray(_useState5, 2),
profileData = _useState6[0],
setProfileData = _useState6[1];
var getProfileData = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var _profileData;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
setIsLoading(true);
_context.prev = 1;
_context.next = 4;
return fetchUserProfile === null || fetchUserProfile === void 0 ? void 0 : fetchUserProfile();
case 4:
_profileData = _context.sent;
setProfileData(_profileData);
setIsLoading(false);
_context.next = 13;
break;
case 9:
_context.prev = 9;
_context.t0 = _context["catch"](1);
setError(_context.t0);
setIsLoading(false);
case 13:
case "end":
return _context.stop();
}
}, _callee, null, [[1, 9]]);
}));
return function getProfileData() {
return _ref2.apply(this, arguments);
};
}();
return {
profileData: profileData,
isLoading: isLoading,
error: error,
getProfileData: getProfileData
};
};