Skip to content

Instantly share code, notes, and snippets.

View Sangrene's full-sized avatar

Hugo Laplace-Builhe Sangrene

View GitHub Profile
function Square(props) { // The properties of the square contain the "onClick" function as well as the "value" number
return (
<button className="square"
onClick={props.onClick}>{/** (1) When I click on the button, it triggers the function onClick from the props object. */}
{props.value}
</button>
);
}
import React from "react";
import { TouchableOpacity, Text, ViewStyle, StyleSheet, StyleProp } from "react-native";
import { fonts } from "../styles";
interface Props{
onPress?() : void;
centerText: string;
backgroundColor: string;
textColor: string;
style?: ViewStyle;
@Sangrene
Sangrene / .npmrc
Created December 17, 2018 13:59
.npmrc for AWS ELB to install dependencies using node-gyp
unsafe-perm=true
@Sangrene
Sangrene / .gitignore
Created December 17, 2018 14:04
Gitignore for NodeJS AWS ELB using /dist as build folder
node_modules
.env
.ebextensions
error.log
dist
import React from "react";
import { View, TouchableOpacity } from "react-native";
class MyChildComponent extends React.Component {
render(){
}
}
@Sangrene
Sangrene / logAction.ts
Created March 21, 2019 15:25
Decorator to log async method
export const logAction = (name: string) => {
return (target, key, descriptor) => {
if(descriptor === undefined){
descriptor = Object.getOwnPropertyDescriptor(target, key);
}
const originalMethod: Function = descriptor.value;
descriptor.value = async function() {
const args: Array<any> = [];
interface ShopModel {
date: string;
}
class Shop extends ShopModel {
constructor(shop: ShopModel){
this.date = shop.date;
}
get formattedDate() {
const bills = createStore([{id: 0, state: 0}, {id: 1, state: 2}]);
const selected = createStore(0);
const cheatersStore = createStoreObject({
bills,
selected
})
const validate = createEvent('validate')
bills.on(validate, (bills, idBill) => {
import React from 'react';
interface Props {
if: boolean;
}
const Conditionnal: React.FC<Props> = props => {
if (props.if) {
return <React.Fragment>{props.children}</React.Fragment>;
} else {
return null;
@Sangrene
Sangrene / findItemAndIndexById.ts
Created December 10, 2019 16:32
Typescript function to extract item & index from an array with items containing an "id" property
const findItemAndIndexById = <T extends { id: string }>(
id: string,
tabWithId: T[]
):
| {
item: T;
index: number;
}
| undefined => {
let itemIndex = -1;