kibana/packages/kbn-react-hooks
Marco Antonio Ghiani 7a69fdd469
[Infra][Logs Explorer] Factor out shared custom hook into a package (#182336)
## 📓 Summary

This work is just the extraction of a utility hook implemented in the
`infra` plugin for re-usability, as there are some scenarios where it
becomes handy in the logs explorer plugin too.

For improved reusability in future, I extracted the useBoolean hook into
a react-hooks package, where additional stateful utility hooks can go in
future.

This also replaces the current usage of the hook in the `infra` plugin
and is used to refactor part of the logs_explorer top nav.

---------

Co-authored-by: Marco Antonio Ghiani <marcoantonio.ghiani@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2024-05-06 16:17:39 +02:00
..
src/use_boolean [Infra][Logs Explorer] Factor out shared custom hook into a package (#182336) 2024-05-06 16:17:39 +02:00
index.ts [Infra][Logs Explorer] Factor out shared custom hook into a package (#182336) 2024-05-06 16:17:39 +02:00
jest.config.js [Infra][Logs Explorer] Factor out shared custom hook into a package (#182336) 2024-05-06 16:17:39 +02:00
kibana.jsonc [Infra][Logs Explorer] Factor out shared custom hook into a package (#182336) 2024-05-06 16:17:39 +02:00
package.json [Infra][Logs Explorer] Factor out shared custom hook into a package (#182336) 2024-05-06 16:17:39 +02:00
README.md [Infra][Logs Explorer] Factor out shared custom hook into a package (#182336) 2024-05-06 16:17:39 +02:00
tsconfig.json [Infra][Logs Explorer] Factor out shared custom hook into a package (#182336) 2024-05-06 16:17:39 +02:00

@kbn/react-hooks

A utility package, @kbn/react-hooks, provides custom react hooks for simple abstractions.

Custom Hooks

useBoolean

Simplify handling boolean value with predefined handlers.

function App() {
  const [value, { on, off, toggle }] = useBoolean();

  return (
    <div>
      <EuiText>
        The current value is <strong>{value.toString().toUpperCase()}</strong>
      </EuiText>
      <EuiFlexGroup>
        <EuiButton onClick={on}>On</EuiButton>
        <EuiButton onClick={off}>Off</EuiButton>
        <EuiButton onClick={toggle}>Toggle</EuiButton>
      </EuiFlexGroup>
    </div>
  );
}