Skip to content

Instantly share code, notes, and snippets.

View behnamazimi's full-sized avatar

Behnam behnamazimi

View GitHub Profile
function MyComponent() {
const ChildComponent = (props) => {...};
return {
ChildComponent
};
}
<MyComponent.ChildComponent>
// ...
</MyComponent.ChildComponent>
function withSomething(Component) {
return function (props) {
return <Component {...props} something="Any" />;
}
}
const WrappedComponent = withSomething(MyComponent);
import React, { useCallback, useEffect, useRef, useState } from "react";
const intervalTime = 1000 / 60;
function TranslateX({ children, from, to, duration }) {
const [x, setX] = useState(from);
const lastTickRef = useRef(0);
useEffect(() => {
function MyComponent({ x, y, children}) {
return children({prop1, prop2, ...});
}
<MyComponent x={2} y={3}>
{(resultProps) => {
return ...
}}
</MyComponent>
function partition(inputArray, callback) {
const result = {};
for (const [indexOfValue, value] of inputArray.entries()) {
const propertyKey = callback(value, indexOfValue);
if (propertyKey === null || propertyKey === '') {
continue;
}
if (!{}.hasOwnProperty.call(result, propertyKey)) {
result[propertyKey] = [];
}
@behnamazimi
behnamazimi / ellipsis-html-sample.html
Last active August 22, 2020 10:17
ellipsis-html Sample with avatars
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ellipsis-html Sample with avatars</title>
<!-- adding library -->
<script src="http://unpkg.com/ellipsis-html/lib/ellipsis-html.min.js"></script>
@behnamazimi
behnamazimi / js-service-wrapper.import.js
Last active June 4, 2020 13:24
js-service-wrapper.import.js
const {ServiceWrapper, ClientHandler, HOOKS} = require("js-service-wrapper");
// ESM
import {ServiceWrapper, ClientHandler, HOOKS} from "js-service-wrapper";