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] = [];
}
const data = {
items: ["A", "B", "C"],
pointerIndex: 0,
next() {
if (this.pointerIndex < this.items.length) // if not done
return { value: this.items[this.pointerIndex++], done: false }
else // if done
return { value: undefined, done: true };
}
}
@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>