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

If React Hooks surport useState(await ...) to getData,we can used in ssr be better #14986

Closed
dazjean opened this issue Mar 1, 2019 · 1 comment

Comments

Projects
None yet
2 participants
@dazjean
Copy link

commented Mar 1, 2019

I am new gay。
we konw Hooks can only be called inside the body of a function component,but if hooks can suppert it we can easy get Default data in ssr,becauces effect not be call by ssr

Example

let APP =  async() => {
    let initState = async () => {
        let response = await fetch('http://localhost:9991/mock/count.json');
        let listData = await response.json();
        return listData.count;
    };
    const [count, setCount] = useState(await initState());
    return (
        <div>
                <span>Count:{count}</span>
        </div>
    );
};


@gaearon

This comment has been minimized.

Copy link
Member

commented Mar 1, 2019

This is planned — although not with this specific API.

https://reactjs.org/blog/2018/11/27/react-16-roadmap.html#suspense-for-server-rendering

@gaearon gaearon closed this Mar 1, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.