Skip to content

Commit cc6d5ce

Browse files
committed
feat: add getDerivedStateFromProps and getSnapshotBeforeUpdate snippets
1 parent bab9800 commit cc6d5ce

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Below is a list of all available snippets and the triggers of each one. The **
4242
| `cwu→` | `componentWillUpdate method` |
4343
| `cdu→` | `componentDidUpdate method` |
4444
| `cwum→` | `componentWillUnmount method` |
45+
| `gdsfp→` | `getDerivedStateFromProps method` |
46+
| `gsbu` | `getSnapshotBeforeUpdate method` |
4547
| `sst→` | `this.setState with object as parameter` |
4648
| `bnd→` | `binds the this of method inside the constructor` |
4749
| `met→` | `simple method` |

snippets/snippets.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@
139139
"",
140140
"const $1: React.SFC<$1Props> = (props) => {",
141141
" return $0;",
142-
"};"
143-
""
142+
"};",
143+
"",
144144
"export default $1;"
145145
],
146146
"description": "Create a React Stateless Functional Component."
@@ -287,5 +287,23 @@
287287
"import { $2 } from '$1';"
288288
],
289289
"description": "Create a import"
290+
},
291+
"getDerivedStateFromProps": {
292+
"prefix": "gdsfp",
293+
"body": [
294+
"static getDerivedStateFromProps(nextProps: ${1:any}, prevState: ${2:any}) {",
295+
" ${0}",
296+
"}"
297+
],
298+
"description": "Invoked right before calling the render method, both on the initial mount and on subsequent updates"
299+
},
300+
"getSnapshotBeforeUpdate": {
301+
"prefix": "gsbu",
302+
"body": [
303+
"static getSnapshotBeforeUpdate(prevProps: ${1:any}, prevState: ${2:any}) {",
304+
" ${0}",
305+
"}"
306+
],
307+
"description": "Invoked right before the most recently rendered output is committed to e.g. the DOM"
290308
}
291309
}

0 commit comments

Comments
 (0)