Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential bug: Passing items from stateful component to receiving reducer #83

Open
lessp opened this issue Aug 4, 2020 · 0 comments
Open

Comments

@lessp
Copy link

lessp commented Aug 4, 2020

Not sure if this is a bug or not, but when passing items from one component to another one ends up with no items, despite them being available in e.g. the initialState-function.

let initialState = items => {
  Console.log(("We've got some items here:", items));
  items;
};

let%component childItem = (~items, ()) => {
  let%hook (allItems, setItems) =
    Hooks.reducer(~initialState=initialState(items), (value, _) => value);

  // Works when using the effect-hook
  /* let%hook () = */
  /*   Hooks.effect( */
  /*     OnMountAndIf((!=), items), */
  /*     () => { */
  /*       setItems(items); */

  /*       None; */
  /*     }, */
  /*   ); */

  <View>
    {allItems
     |> List.map(item => <Text style=Style.[color(Colors.red)] text=item />)
     |> React.listToElement}
  </View>;
};

let%component container = () => {
  let%hook (items, setItems) = React.Hooks.state([]);

  let%hook () =
    Hooks.effect(
      OnMount,
      () => {
        setItems(_prev => ["One", "Two", "Three"]);

        None;
      },
    );

  <childItem items />;
};
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

No branches or pull requests

1 participant