Skip to content

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