1
0
Fork 0
mirror of synced 2024-12-26 08:43:19 -05:00
ultimate-vim/sources_non_forked/vim-snippets/snippets/javascript/javascript-react.snippets

191 lines
2.9 KiB
Text
Raw Normal View History

2020-12-04 16:15:32 -05:00
# Import
snippet ir import React
2016-11-09 12:22:55 -05:00
import React from 'react';
2020-12-04 16:15:32 -05:00
snippet irc import React and Component
2019-08-22 11:36:17 -04:00
import React, { Component } from 'react';
2020-12-04 16:15:32 -05:00
snippet irh import React hooks
import { use$1 } from 'react';
snippet ird import ReactDOM
2016-11-09 12:22:55 -05:00
import ReactDOM from 'react-dom';
2020-12-04 16:15:32 -05:00
snippet irp import PropTypes
import PropTypes from 'prop-types';
# Lifecycle Methods
snippet cdm componentDidMount
2016-11-09 12:22:55 -05:00
componentDidMount() {
${1}
2020-12-04 16:15:32 -05:00
};
snippet cdup componentDidUpdate
2016-11-09 12:22:55 -05:00
componentDidUpdate(prevProps, prevState) {
${1}
2020-12-04 16:15:32 -05:00
};
snippet cwm componentWillMount
2016-11-09 12:22:55 -05:00
componentWillMount() {
${1}
2020-12-04 16:15:32 -05:00
};
snippet cwr componentWillReceiveProps
2016-11-09 12:22:55 -05:00
componentWillReceiveProps(nextProps) {
${1}
2020-12-04 16:15:32 -05:00
};
snippet cwun componentWillUnmount
2016-11-09 12:22:55 -05:00
componentWillUnmount() {
${1}
2020-12-04 16:15:32 -05:00
};
snippet cwu componentWillUpdate
2016-11-09 12:22:55 -05:00
componentWillUpdate(nextProps, nextState) {
${1}
2020-12-04 16:15:32 -05:00
};
snippet scu shouldComponentUpdate
shouldComponentUpdate(nextProps, nextState) {
${1}
2016-11-09 12:22:55 -05:00
}
2020-12-04 16:15:32 -05:00
# Props
snippet spt static propTypes
static propTypes = {
${1}: PropTypes.${2}
};
snippet pt propTypes
${1}.propTypes = {
${2}: PropTypes.${2}
};
snippet sdp static defaultProps
2016-11-09 12:22:55 -05:00
static defaultProps = {
2020-12-04 16:15:32 -05:00
${1}: ${2}
};
snippet dp defaultProps
${1}.defaultProps = {
${2}: ${3}
};
snippet pp props
props.${1};
snippet tp this props
this.props.${1};
# State
2016-11-09 12:22:55 -05:00
snippet st
state = {
${1}: ${2},
2020-12-04 16:15:32 -05:00
};
snippet sst
this.setState({
${1}: ${2}
});
snippet tst
this.state.${1};
# Component
snippet raf
2019-08-22 11:36:17 -04:00
const ${1:ComponentName} = (${2:props}) => {
2020-12-04 16:15:32 -05:00
${3:state}
2019-08-22 11:36:17 -04:00
return (
2020-12-04 16:15:32 -05:00
<>
${4}
</>
2019-08-22 11:36:17 -04:00
);
2020-12-04 16:15:32 -05:00
};
2019-08-22 11:36:17 -04:00
2020-12-04 16:15:32 -05:00
snippet rcla
class ${1:ClassName} extends Component {
2016-11-09 12:22:55 -05:00
render() {
return (
2020-12-04 16:15:32 -05:00
<>
${2}
</>
2016-11-09 12:22:55 -05:00
);
}
}
2020-12-04 16:15:32 -05:00
snippet ercla
export default class ${1:ClassName} extends Component {
2016-11-09 12:22:55 -05:00
render() {
return (
2020-12-04 16:15:32 -05:00
<>
${2}
</>
2016-11-09 12:22:55 -05:00
);
2020-12-04 16:15:32 -05:00
};
};
2016-11-09 12:22:55 -05:00
snippet ctor
constructor() {
super();
2020-12-04 16:15:32 -05:00
${1:state}
2016-11-09 12:22:55 -05:00
}
2020-12-04 16:15:32 -05:00
2016-11-09 12:22:55 -05:00
snippet ren
render() {
return (
2020-12-04 16:15:32 -05:00
<>
${2}
</>
2016-11-09 12:22:55 -05:00
);
}
2020-12-04 16:15:32 -05:00
snippet fup
forceUpdate(${1:callback});
# Hooks
snippet uses useState
const [${1:state}, set${2}] = useState(${3:initialState});
snippet usee useEffect
useEffect(() => {
2016-11-09 12:22:55 -05:00
${1}
2020-12-04 16:15:32 -05:00
});
snippet userd useReducer
const [${1:state}, ${2:dispatch}] = useReducer(${3:reducer});
snippet userf useRef
const ${1:refContainer} = useRef(${2:initialValue});
snippet usect useContext
const ${1:value} = useContext(${2:MyContext});
snippet usecb useCallback
const ${1:memoizedCallback} = useCallback(
() => {
${2}(${3})
},
[$3]
);
snippet usem useMemo
const ${1:memoizedCallback} = useMemo(() => ${2}(${3}), [$3]);
snippet usei useImperativeHandle
useImperativeHandle(${1:ref}, ${2:createHandle});
snippet used useDebugValue
useDebugValue(${1:value});
# ReactDOM methods
snippet rdr ReactDOM.render
ReactDOM.render(${1}, ${2});
snippet rdh ReactDOM.hydrate
ReactDOM.hydrate(${1:element}, ${2:container}[, ${3:callback}]);
snippet rdcp ReactDOM.createPortal
ReactDOM.createPortal(${1:child}, ${2:container});