-
{ this.state.data.title }+
-
- {
- this.state.data.content
- }
+ return !this.state.visible ? null : (
+
+
+
+ {this.state.data.title}
+
+ +
+
+
+
{this.state.data.content}
-
+ );
}
componentDidMount() {
document.addEventListener('modal', this.modalHandler);
@@ -107,11 +111,13 @@ class ModalDialog extends React.Component {
});
}
static show(data) {
- document.dispatchEvent(new CustomEvent('modal', {
- detail: {
- data
- }
- }));
+ document.dispatchEvent(
+ new CustomEvent('modal', {
+ detail: {
+ data
+ }
+ })
+ );
}
modalClick() {
if (this.state.data.closeOnClick) this.close();
@@ -121,20 +127,21 @@ class ModalDialog extends React.Component {
```jsx
// add to render function
-
+
;
// every time you wanna call the dialog
// content is a jsx element
ModalDialog.show({
title: 'Hello, world!',
closeOnClick: true,
- content:

-});
+ content:

+});
```
#### Notes:
-* This component includes a lot of CSS, which might conflict with other CSS in your project. It is recomended for the modal to be a direct child of the body tag.
-* A more up-to-date method with lower compatibility is to use [Portals](https://reactjs.org/docs/portals.html) in React 16+.
+
+- This component includes a lot of CSS, which might conflict with other CSS in your project. It is recomended for the modal to be a direct child of the body tag.
+- A more up-to-date method with lower compatibility is to use [Portals](https://reactjs.org/docs/portals.html) in React 16+.
diff --git a/static-parts/README-end.md b/static-parts/README-end.md
index b913aa3b3..482211fdd 100644
--- a/static-parts/README-end.md
+++ b/static-parts/README-end.md
@@ -1,5 +1,5 @@
------
+---
-*This repository is a work in progress. If you want to contribute, please check the open issues to see where and how you can help out!*
+_This repository is a work in progress. If you want to contribute, please check the open issues to see where and how you can help out!_
-*This README is built using [markdown-builder](https://github.com/30-seconds/markdown-builder).*
\ No newline at end of file
+_This README is built using [markdown-builder](https://github.com/30-seconds/markdown-builder)._
diff --git a/static-parts/README-start.md b/static-parts/README-start.md
index 4f524a7bb..924890677 100644
--- a/static-parts/README-start.md
+++ b/static-parts/README-start.md
@@ -4,13 +4,14 @@
> Curated collection of useful React snippets that you can understand in 30 seconds or less.
-* Use
Ctrl +
F or
command +
F to search for a snippet.
-* Contributions welcome, please read the [contribution guide](CONTRIBUTING.md).
-* Snippets are written in React 16.8+, using hooks.
+- Use
Ctrl +
F or
command +
F to search for a snippet.
+- Contributions welcome, please read the [contribution guide](CONTRIBUTING.md).
+- Snippets are written in React 16.8+, using hooks.
### Prerequisites
To import a snippet into your project, you must import `React` and copy-paste the component's JavaScript code like this:
+
```js
import React from 'react';
@@ -20,19 +21,21 @@ function MyComponent(props) {
```
If there is any CSS related to your component, copy-paste it to a new file with the same name and the appropriate extension, then import it like this:
+
```js
import './MyComponent.css';
```
To render your component, make sure there is a node with and id of `"root"` present in your element (preferrably a `
`) and that you have imported `ReactDOM`, like this:
+
```js
import ReactDOM from 'react-dom';
```
#### Related projects
-* [30 Seconds of Code](https://30secondsofcode.org)
-* [30 Seconds of CSS](https://30-seconds.github.io/30-seconds-of-css/)
-* [30 Seconds of Interviews](https://30secondsofinterviews.org/)
+- [30 Seconds of Code](https://30secondsofcode.org)
+- [30 Seconds of CSS](https://30-seconds.github.io/30-seconds-of-css/)
+- [30 Seconds of Interviews](https://30secondsofinterviews.org/)
## Table of Contents