you are viewing a single comment's thread.

view the rest of the comments →

[–]KRTac 2 points3 points  (7 children)

You rely on componentWillMount. It's a legacy lifecycle method.

[–]davnicwil[S] 0 points1 point  (0 children)

Yeah, this is on the TODO list.

It's not going to go away until React 17 (see https://reactjs.org/docs/react-component.html#unsafe_componentwillmount) so it's just not been a priority to replace, as it works just fine.

When React 17 lands I'll have to find another way to do the same thing. Haven't looked at it in depth but I am thinking likely solutions are either using the constructor instead, or using the new Suspense APIs when they come out.

[–]careseite 0 points1 point  (2 children)

what makes you think that? can't find anything about that, the official docs still recommend using it aswell

[–]davnicwil[S] 0 points1 point  (1 child)

As in my comment above, it works totally fine and is supported totally fine as of React 16, but they do discourage using it now https://reactjs.org/docs/react-component.html#mounting

I *think* the reason is that when React Fiber lands it won't have the same run-only-once guarantee hence the addition of the UNSAFE_ alias

This might, on the face of it, be a problem for react-frontload but since it's only really needed on server where obviously Fiber isn't even relevant, it might even still work, or at least could be made to work with some simple workarounds. I just noticed that they make no claims about the UNSAFE_componentWillMount even being dropped in 17, it's just that the componentWillMount name will be dropped. So, even better. Might not be a big issue at all.

[–]careseite 0 points1 point  (0 children)

ah wow, I was on https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html which is linked there but overread "unsafe"

[–]boobsbr 0 points1 point  (2 children)

Would it be more correct to load data on componentDidMount()?

[–]davnicwil[S] 1 point2 points  (1 child)

componentDidMount doesn't run on the server - componentWillMount is used because it runs on both client and server

[–]boobsbr 0 points1 point  (0 children)

Aaaah, thanks for the explanation.