Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Guilherme R Vasconcelos guilherme6191

🏠
Working from home
View GitHub Profile
View flatten.js
// could be in the context of a project or just a separate js file to be run with node ${fileName}
// for the first, the tools to run and result the tests really depend on the project setup
// for the latter, the tests would have to be commented out and lines 15 and 16 uncommented
/**
* Returns flattened array
* @param {*} arr with arr elements
*/
export const flatten = arr => {
const doFlatten = () => {
@guilherme6191
guilherme6191 / tslint.json
Created Feb 14, 2019
tslint for React App
View tslint.json
{
"extends": ["tslint:recommended", "tslint-react"],
"rulesDirectory": ["tslint-plugin-prettier"],
"linterOptions": {
"exclude": [
"config/**/*.js",
"dist",
"tmp",
"node_modules/**/*.ts",
"node_modules/**/*.tsx",
@guilherme6191
guilherme6191 / useField.js
Created Jan 14, 2019
React hook for form field state
View useField.js
const useField = initial => {
const [value, set] = useState(initial);
return {
value,
set,
reset: () => set(initial),
bind: {
value,
onChange: e => set(e.target.value)
@guilherme6191
guilherme6191 / App.js
Created Mar 28, 2018
React Context API
View App.js
import React, { Component } from 'react';
// first we will make a new context
const MyContext = React.createContext();
// Then create a provider Component
class MyProvider extends Component {
state = {
name: 'Wes',
age: 100,
View ErrorBoundary.jsx
import React from 'react';
export default class ErrorBoundary extends React.Component {
constructor(props) {
super();
this.state = { error: null, errorInfo: null };
}
componentDidCatch(error, info) {
this.setState({
error,
@guilherme6191
guilherme6191 / codePen1.jsx
Last active Apr 20, 2017
Codepen React Fundamentals - Code:1
View codePen1.jsx
class HelloWorld extends React.Component {
render() {
const name = 'Sr(a) ' + this.props.name
return <h1>Hello, {name}!!</h1>;
}
}
ReactDOM.render(
<HelloWorld name="Joao"/>,
document.getElementById('root')
@guilherme6191
guilherme6191 / Basic React Component wrapper for react-bootstrap Modal.
Last active Mar 16, 2017
Wrapper for react-bootstrap-modal. Easier to use this way throughout your app. Different customizations might be needed depending on your needs.