Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 761 Bytes

useFirstMountState.md

File metadata and controls

34 lines (27 loc) · 761 Bytes

useFirstMountState

Returns true if component is just mounted (on first build) and false otherwise.

Installation

dependencies:
  flutter_use: ^0.0.2

Usage

class Sample extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final isFirstMount = useFirstMountState();
    final update = useUpdate();

    return Column(
      children: [
        Text("This component is just mounted: ${isFirstMount ? 'YES' : 'NO'}"),
        ElevatedButton(
          onPressed: () => update(),
          child: const Text('Rebuild'),
        ),
      ]
    );
  }
}