Skip to content
New issue

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

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

Already on GitHub? # to your account

Context bug in SSR #1380

Closed
yuanyan opened this issue Sep 18, 2019 · 3 comments
Closed

Context bug in SSR #1380

yuanyan opened this issue Sep 18, 2019 · 3 comments
Assignees
Labels

Comments

@yuanyan
Copy link
Collaborator

yuanyan commented Sep 18, 2019

Help us to manage our issues by answering the following:

  1. How would you tag this issue?
  • Bug
  1. Describe your issue:
const ThemeContext = createContext('light');

function MyContext() {
  return (
    <ThemeContext.Provider value={'dark'}>
      <MyComponent />
    </ThemeContext.Provider>
  );
};

function MyComponent() {
  return (
    <ThemeContext.Consumer>
      {value => <div>{value}</div>}
    </ThemeContext.Consumer>
  );
};

function MyContext2() {
  const value = useContext(ThemeContext);
  return <div>{value}</div>
}

function MyComponent2() {
  return (
    [
      <MyContext />,
      <MyContext2 />
    ]
  );
};

const str = renderToString(<MyComponent2 />);
// current output: <div>dark</div><div>dark</div>
// expect to: <div>dark</div><div>light</div>
.
@yuchonghua
Copy link

#889

@yuanyan
Copy link
Collaborator Author

yuanyan commented Sep 25, 2019

fixed in #1378

@yuchonghua
Copy link

其实不是很理解, expect to:

dark
light

为什么SSR的时候class组件不应该读取Context

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants