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

children[0] is not a function #21

Open
lake2 opened this issue Oct 11, 2019 · 4 comments
Open

children[0] is not a function #21

lake2 opened this issue Oct 11, 2019 · 4 comments

Comments

@lake2
Copy link

lake2 commented Oct 11, 2019

the sample code to reproduce the issue:
https://codesandbox.io/s/wonderful-edison-147v9

What should I do if I want inject one store and use it by context?

@lake2
Copy link
Author

lake2 commented Oct 14, 2019

Is there anyone can help me? That will be appreciated.

@philmander
Copy link
Collaborator

Forgive me, I'm a bit rusty on this. The issue is fixed if you remove <Observer>. I'm not sure if this because of a problem with Observer, the way you're using it or a Preact 10 compatibility issue.

You can do this as an alternative:

const App = observer(() => {
  const store = useStore();
  return (
      <div>{store.a}</div>
  );
});

@lake2
Copy link
Author

lake2 commented Oct 15, 2019

Thanks! Can useMemo and useCallback work when component is be wrapped ?

@libaoxu
Copy link

libaoxu commented Jul 30, 2024

it because the code have bug where the code location is Observer

origin

export const Observer = observer(({ children }) => children[0]() );

if you only have one child, children is not a array, so fix it by

after

export const Observer = observer(({ children }) => typeof children === "function" ?  children() : children[0]() );

finally that is perfect success

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

3 participants