title: How to initialize stateProvider from constructor in RiverPod
body: <p>Basically, I want to set the initial constructor value to <code>StateProvider</code> so I can use it in its child widgets.</p>
  <pre><code>final stateProvider = StateProvider((ref) =&gt; &quot;default&quot;);
  
  class ExampleWidget extends ConsumerWidget {
  
    ExampleWidget({required String text}){
      // how to override default hear as
      // stateProvider = text
    }
  
    @override
    Widget build(BuildContext context, ScopedReader watch) {
      return Column(
        children: [
          Text(watch(stateProvider).state),
          Container(
            child: ChildWidget(),
          ),
        ],
      );
    }
  }
  
  class ChildWidget extends ConsumerWidget {
    @override
    Widget build(BuildContext context, ScopedReader watch) {
      return Container(
        child: Text(watch(stateProvider).state),
      );
    }
  }
  </code></pre>
  <p>So how do I implement this?</p>
  <p>I have tried <a href="https://github.com/rrousselGit/river_pod/issues/295#issuecomment-770368500" rel="nofollow noreferrer">this</a> but the state value is not updating.</p>
  <p>Edit ----------------</p>
  <p>With <code>riverpod_hook</code> &amp; <code>hooks_flutter</code></p>
  <pre><code>final stateProvider = StateProvider((ref) =&gt; &quot;default&quot;);
  
  class ExampleWidget extends HookWidget {
  
    @override
    Widget build(BuildContext context) {
      WidgetsBinding.instance?.addPostFrameCallback((_) {
        useEffect((){
          context.read(stateProvider).state = &quot;new value&quot;;
        },[]);
      });
  
      final state = useProvider(stateProvider).state;
      return Column(
        children: [
          Text(state),
        ],
      );
    }
  }
  </code></pre>
  <p>above code throwing this error</p>
  <p><code>Hooks can only be called from the build method of a widget that mix-in </code>Hooks``</p>
  <p>So I tried to initialize under the build method like this</p>
  <pre><code>useEffect((){
     context.read(stateProvider).state = &quot;new value&quot;;
  },[]);
  </code></pre>
  <p>but above code throws the following error:</p>
  <pre><code>The following Error was thrown building ExampleWidget(dirty, dependencies: [UncontrolledProviderScope]):
  Instance of 'Error'
  </code></pre>
  <p>I just want to initialize the value once that's why I want to use <code>useEffect</code> hook.</p>