Skip to content

Add useDebugValue hook #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add useDebugValue hook
  • Loading branch information
seanyu4296 committed Apr 30, 2020
commit e2ad0ca59eb16c1563aaafed1d98044039b33138
2 changes: 2 additions & 0 deletions src/React/Basic/Hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ exports.useLazy_ = function (eq, deps, computeA) {
return React.useMemo(computeA, [memoizedKey]);
};

exports.useDebugValue_ = React.useDebugValue;

exports.unsafeSetDisplayName = function (displayName, component) {
component.displayName = displayName;
component.toString = function () {
Expand Down
21 changes: 19 additions & 2 deletions src/React/Basic/Hooks.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module React.Basic.Hooks
, UseMemo
, useLazy
, UseLazy
, useDebugValue
, UseDebugValue
, UnsafeReference(..)
, displayName
, module React.Basic.Hooks.Internal
Expand Down Expand Up @@ -171,8 +173,7 @@ useState' ::
forall state.
state ->
Hook (UseState state) (state /\ (state -> Effect Unit))
useState' initialState =
useState initialState <#> rmap (_ <<< const)
useState' initialState = useState initialState <#> rmap (_ <<< const)

foreign import data UseState :: Type -> Type -> Type

Expand Down Expand Up @@ -285,6 +286,15 @@ useLazy deps computeA = unsafeHook (runEffectFn3 useLazy_ (mkFn2 eq) deps comput

foreign import data UseLazy :: Type -> Type -> Type -> Type

-- | Use this hook to display a label for custom hooks in React DevTools
useDebugValue :: forall a. a -> (a -> String) -> Hook (UseDebugValue a) Unit
useDebugValue debugValue display = unsafeHook (runEffectFn2 useDebugValue_ debugValue display)

useDebugValue' :: forall a. Show a => a -> Hook (UseDebugValue a) Unit
useDebugValue' debugValue = useDebugValue debugValue show

foreign import data UseDebugValue :: Type -> Type -> Type

newtype UnsafeReference a
= UnsafeReference a

Expand Down Expand Up @@ -395,3 +405,10 @@ foreign import useLazy_ ::
deps
(Unit -> a)
a

foreign import useDebugValue_ ::
forall a.
EffectFn2
a
(a -> String)
Unit