Skip to content

Instantly share code, notes, and snippets.

View OtayNacef's full-sized avatar
🎯
Focusing

Nacef Otay OtayNacef

🎯
Focusing
View GitHub Profile
@OtayNacef
OtayNacef / Pagination.js
Last active February 7, 2021 19:53
React Hooks Pagination
import React, { useState, useEffect } from "react";
const LEFT_PAGE = "LEFT";
const RIGHT_PAGE = "RIGHT";
const range = (from, to, step = 1) => {
let i = from;
const range = [];
while (i <= to) {
range.push(i);
i += step;
import { ChangeEvent, FC, useState } from "react";
import data from "./data.json";
import styled from "styled-components";
import { FaArrowDown } from "@react-icons/all-files/fa/FaArrowDown";
import {
AutoCompleteContainer,
AutoCompleteIcon,
Input,
AutoCompleteItem,
import react, { ChangeEvent, FC, useState } from "react";
import styled from "styled-components";
import { FaArrowDown } from "@react-icons/all-files/fa/FaArrowDown";
import {
AutoCompleteContainer,
AutoCompleteIcon,
Input,
AutoCompleteItem,
AutoCompleteItemButton
@OtayNacef
OtayNacef / isCached
Created February 21, 2021 19:34
Express middleware caching
import { Response, Request, NextFunction } from 'express';
import * as redis from 'redis';
const portRedis = process.env.PORT_REDIS || '6379';
const redisClient = redis.createClient(portRedis);
const isCached = (req: Request, res: Response, next: NextFunction) => {
const { idUser } = req.params;
import React from 'react'
const App = () => {
return (
<h1>
Create React App Without CRA ☘️
</h1>
)
}
@OtayNacef
OtayNacef / index.js
Last active March 7, 2021 20:36
React App without CRA
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
ReactDOM.render(<App />, document.getElementById("app"));
// hot reloading. It works by replacing a module of the application
// during runtime with an updated one so that it’s available for instant use.
module.hot.accept();
const webpack = require("webpack");
const path = require("path");
module.exports = {
entry: path.resolve(__dirname, "./src/index.js"),
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
@OtayNacef
OtayNacef / package.json
Created March 7, 2021 21:05
React without CRA
{
"name": "react-without-cra",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack serve --config ./webpack.config.js --mode development --port 3000"
},
"keywords": [],
"author": "",
@OtayNacef
OtayNacef / tsconfig.json
Created March 11, 2021 09:27
React TypeScript Without CRA
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node",
@OtayNacef
OtayNacef / webpack.config.ts
Last active March 17, 2021 22:46
React Typescript Webpack
import path from "path";
import { Configuration, DefinePlugin } from "webpack";
import HtmlWebpackPlugin from "html-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import TsconfigPathsPlugin from "tsconfig-paths-webpack-plugin";
const webpackConfig = (): Configuration => ({
entry: "./src/index.tsx",
...(process.env.production || !process.env.development
? {}