Skip to content

Commit 6d666fc

Browse files
committed
solution for Portals excersize
1 parent bc3d17f commit 6d666fc

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

exercises/src/portals/01-using-modals/src/App.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const App = (props) => {
88
<div>
99
<Header />
1010
<Main />
11+
<div id="modal"></div>
1112
</div>
1213
);
1314
}

exercises/src/portals/01-using-modals/src/Modal.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import ReactDOM from 'react-dom';
23

34
class Modal extends React.Component {
45

@@ -7,16 +8,21 @@ class Modal extends React.Component {
78
return null;
89
}
910

10-
const modalStyle = {
11-
background: 'transparent',
12-
width: '100%',
13-
textAlign: 'center'
14-
};
11+
const modalStyle = {
12+
background: 'transparent',
13+
position: 'absolute',
14+
top: 200,
15+
width: '100%',
16+
textAlign: 'center'
17+
};
1518

1619

17-
return <div style={modalStyle} >
20+
return ReactDOM.createPortal(
21+
<div style={modalStyle} >
1822
{this.props.children}
19-
</div>;
23+
</div>,
24+
document.getElementById('modal'),
25+
);
2026
}
2127
}
2228

0 commit comments

Comments
 (0)