In React, how do I detect if my component is rendering from the client or the server?

前端 未结 9 1153
夕颜
夕颜 2020-12-29 18:41

I\'m building a isomorphic application, but I\'m using a third-party component that only renders on the client. So, particularly for this component, I need to only render it

9条回答
  •  生来不讨喜
    2020-12-29 19:16

    if (typeof window === "undefined") { //client side code }
    

    Without typeof you'll get an error.

提交回复
热议问题