Skip to content

toggle: useCallback should use inputs#1

Open
langpavel wants to merge 1 commit intokalcifer:masterfrom
langpavel:patch-1
Open

toggle: useCallback should use inputs#1
langpavel wants to merge 1 commit intokalcifer:masterfrom
langpavel:patch-1

Conversation

@langpavel
Copy link

No description provided.

@langpavel
Copy link
Author

Not in this PR but seen this in react-use — except this is for flow:

// @flow

import { useState, useCallback } from 'react';

export default function useToggle(initialValue: boolean = false) {
  const [value, setValue] = useState(initialValue);
  const toggleValue = useCallback(
    (newVal: ?boolean) =>
      setValue(val => (typeof newVal === 'boolean' ? newVal : !val)),
    [setValue],
  );
  return [value, toggleValue];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant