|
1 | 1 | // @flow |
2 | | -/* eslint-disable react/forbid-prop-types */ |
| 2 | +/* eslint-disable react/forbid-prop-types, react/no-unused-prop-types */ |
3 | 3 | import React, {useRef, useEffect, useLayoutEffect} from 'react'; |
4 | 4 | import PropTypes from 'prop-types'; |
5 | 5 | import {useElementsContextWithUseCase} from './Elements'; |
@@ -42,10 +42,10 @@ const useCallbackReference = (cb: MixedFunction) => { |
42 | 42 | }; |
43 | 43 | }; |
44 | 44 |
|
45 | | -const createElementComponent = (type: string) => { |
| 45 | +const createElementComponent = (type: string, isServer: boolean) => { |
46 | 46 | const displayName = `${capitalized(type)}Element`; |
47 | 47 |
|
48 | | - const Element = (props: Props) => { |
| 48 | + const ClientElement = (props: Props) => { |
49 | 49 | const { |
50 | 50 | id, |
51 | 51 | className, |
@@ -122,6 +122,16 @@ const createElementComponent = (type: string) => { |
122 | 122 | return <div id={id} className={className} ref={domNode} />; |
123 | 123 | }; |
124 | 124 |
|
| 125 | + // Only render the Element wrapper in a server environment. |
| 126 | + const ServerElement = (props: Props) => { |
| 127 | + // Validate that we are in the right context by calling useElementsContextWithUseCase. |
| 128 | + useElementsContextWithUseCase(`mounts <${displayName}>`); |
| 129 | + const {id, className} = props; |
| 130 | + return <div id={id} className={className} />; |
| 131 | + }; |
| 132 | + |
| 133 | + const Element = isServer ? ServerElement : ClientElement; |
| 134 | + |
125 | 135 | Element.propTypes = { |
126 | 136 | id: PropTypes.string, |
127 | 137 | className: PropTypes.string, |
|
0 commit comments