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

前端 未结 9 1291
夕颜
夕颜 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:41

    You can check if global window variable is defined or not. as in browser it should always be defined.

    var isBrowser = window!==undefined
    

提交回复
热议问题