Skip to content

Instantly share code, notes, and snippets.

View Arkellys's full-sized avatar
☄️
.* ✦ ₊ ⭑. ˚ * ★ .˚  🪐 . ⭑ .   ˚

Arkellys

☄️
.* ✦ ₊ ⭑. ˚ * ★ .˚  🪐 . ⭑ .   ˚
View GitHub Profile
@Arkellys
Arkellys / README.md
Last active March 19, 2024 09:23
Example of bash script to create a new React (sub-)component file and folder and add the export into an index file automatically.

The script will allow creating a new component in the folder src/components. If the given path ends with a component name (detection is made if the last part of the path is in PascalCase), then it will detect the new component created is a sub-component and put it in an subComponents folder. A new export is automatically added (and sorted alphabetically) into the index.js file of the parent folder.

Variables

  • validFolders → List of folders where a new component can be created
  • subComponentFolderName → Name of the folder for sub-components

Example

Initial folder structure:

@Arkellys
Arkellys / REG.md
Last active May 17, 2024 15:34
A short guide to answer some of the most common questions and issues on React+Electron apps.
@Arkellys
Arkellys / useStateWithEffect.js
Last active May 17, 2023 07:10
Custom hook like `useState()` but updates the state when the initial value changes.
import { useEffect, useState } from "react";
/**
* Returns like `useState()` but updates the state when the initial value changes.
* @param {any} initialValue - Initial value of the state
* @returns {Array.<any,Function>} State value and setter
*/
export function useStateWithEffect(initialValue) {
@Arkellys
Arkellys / comment.js
Created November 14, 2022 09:06
Very simple remark plugins for tags, mentions and comment.
import { findAndReplace } from "mdast-util-find-and-replace";
const commentRegex = /\/\/([^\n\\/]*)\/\//g; // //<value>//
export default function () {
function replaceComment(_match, text) {
return {
type: "span",
data: {
hName: "comment",
@Arkellys
Arkellys / change-entry-point.js
Last active October 21, 2022 08:08
Script to change the entry point (main) in `package.json` using an environment variable.
const { readFileSync, writeFileSync } = require("fs");
try {
const filePath = "./package.json";
const entryPath = process.env.ENTRY_PATH;
let data = readFileSync(filePath, "utf8");
data = JSON.parse(data);
if (data.main !== entryPath) {
@Arkellys
Arkellys / 1. useForm.js
Last active November 15, 2022 06:29
Custom hook to handle forms' submit with custom validators compatible with react-bootstrap (v2.5.0)
import { isEmpty } from "lodash";
import { useState } from "react";
/**
* Submits a form.
* @callback Submit
* @param {import("react").SyntheticEvent} event - Form event
* @param {Function} callback - Method called when the form is valid on submit
*/