Skip to content

Instantly share code, notes, and snippets.

View mohandere's full-sized avatar
🎯
Focusing

Mohan Dere mohandere

🎯
Focusing
View GitHub Profile
@mohandere
mohandere / settings.json
Created August 20, 2019 15:35
Sublime 3 user settings
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"caret_extra_bottom": 1,
"caret_extra_top": 1,
"caret_extra_width": 1,
"caret_style": "blink",
"color_scheme": "Packages/Colorsublime - Themes/LAZY.tmTheme",
"create_window_at_startup": false,
"fade_fold_buttons": false,
@mohandere
mohandere / settings.json
Created August 20, 2019 15:12
VS code editor 2019 settings mac os
// Place your settings in this file to overwrite the default settings
{
"editor.wordWrap": "on",
"editor.tabSize": 2,
"editor.mouseWheelZoom": false,
"guides.enabled": false,
"terminal.integrated.fontSize": 17,
"editor.fontSize": 20,
"window.zoomLevel": 0,
"sublimeTextKeymap.promptV3Features": true,
import hoistNonReactStatic from 'hoist-non-react-statics';
const withSearch = (WrappedComponent) => {
class WithSearch extends React.Component {/*...*/}
hoistNonReactStatic(EithSearch, WrappedComponent);
return WithSearch;
}
// Define a static method
ProductsList.staticMethod = function() {/*...*/}
render() {
// A new version of ProductsListWithSearch is created on every render
const ProductsListWithSearch = withSearch(ProductsList);
// That causes the entire subtree to unmount/remount each time!
return <ProductsListWithSearch />;
}
@mohandere
mohandere / hoc-withSearch.js
Last active May 12, 2019 14:56
Higher-Order Components
const withSearch = WrappedComponent => {
class WithSearch extends React.Component {
state = {
searchTerm: ""
};
handleSearch = event => {
this.setState({ searchTerm: event.target.value });
};
render() {
@mohandere
mohandere / hoc-ProductsList.js
Last active May 12, 2019 14:53
Higher-Order Component
const ProductsList = (props) => {
let { data: products } = props;
return (
<div>
<div>
<div>
<h2>Products</h2>
</div>
</div>
<div>
@mohandere
mohandere / hoc-ProductsWithSearch.js
Last active May 12, 2019 14:34
Higher-Order Component
import products from './products.json'
class ProductsListWithSearch extends React.PureComponent {
state = {
searchTerm: ''
}
handleSearch = event => {
this.setState({ searchTerm: event.target.value })
}
render() {
const ProductCard = props => {
return (
<div className="product">
<p>
<b>Title:</b> {props.title}
</p>
<p>
<b>Style:</b> {props.style}
</p>
<p>
@mohandere
mohandere / hoc-ppHOC.js
Last active May 7, 2019 14:21
Higher Order Components
const propsProxyHOC = (WraapperComponent) => {
return class extends React.Component {
state = {
count: 0
}
render() {
// Pass thru the props that the HOC receives
return <WraapperComponent {...this.props} {...this.state} />
}
}
@mohandere
mohandere / hoc-withSearch-full-example.js
Last active May 12, 2019 14:26
Higher-Order Components
const ProductCard = props => {
return (
<div>
<hr />
<p>
<b>Title:</b> {props.title}
</p>
<p>
<b>Style:</b> {props.style}
</p>