Skip to content

Instantly share code, notes, and snippets.

View abhishekjakhar's full-sized avatar
:octocat:

Abhishek Jakhar abhishekjakhar

:octocat:
View GitHub Profile
import { Suspense, lazy, memo, Children } from 'react';
import { createFileMap } from './createFileMap';
const SandpackRoot = lazy(() => import('./SandpackRoot'));
type PlaygroundProps = {
children: React.ReactNode;
};
import type { SandpackFile } from '@codesandbox/sandpack-react';
export const createFileMap = (codeSnippets: React.ReactElement[]) => {
return codeSnippets.reduce(
(result: Record<string, SandpackFile>, codeSnippet: React.ReactElement) => {
if (codeSnippet.type !== 'pre') {
return result;
}
const { props } = codeSnippet.props.children;
@abhishekjakhar
abhishekjakhar / Description.js
Created June 17, 2019 00:55
React Fragment (Description Component)(Keyed Fragment)
import React from 'react';
const teachers = [
{ id: 1, name: 'Abhishek', subject: 'React' },
{ id: 2, name: 'Aakash', subject: 'JavaScript' }
]
const Description = () => (
<dl>
{
@abhishekjakhar
abhishekjakhar / TableColumns.js
Created June 16, 2019 17:22
React Fragment (Table Columns Component) (div)
import React from 'react';
const TableColumns = (props) => {
const { name, subject } = props;
return (
<div>
<td>{name}</td>
<td>{subject}</td>
</div>
@abhishekjakhar
abhishekjakhar / TableColumns.js
Last active June 16, 2019 17:21
React Fragment (Table Columns Component) (React.Fragment)
import React from 'react';
const TableColumns = (props) => {
const { name, subject } = props;
return (
<React.Fragment>
<td>{name}</td>
<td>{subject}</td>
</React.Fragment>
@abhishekjakhar
abhishekjakhar / Table.js
Last active June 17, 2019 00:21
React Fragment (Table Component)
import React from 'react';
import TableColumns from './TableColumns';
const teachers = [
{ id: 1, name: 'Abhishek', subject: 'React' },
{ id: 2, name: 'Aakash', subject: 'JavaScript' }
]
const Table = () => (
@abhishekjakhar
abhishekjakhar / index.css
Last active May 5, 2019 05:49
index.css (Mocktail App)
@import url('https://fonts.googleapis.com/css?family=Quicksand:400,500,700');
/* Basic */
*,
*::after,
*:before {
margin: 0;
padding: 0;
box-sizing: inherit;
@abhishekjakhar
abhishekjakhar / Spinner.js
Last active May 2, 2019 04:02
Spinner.js (Mocktail App)
import React from 'react';
const Spinner = () => (
<div className="spinner">
<div className="bounce1"></div>
<div className="bounce2"></div>
<div className="bounce3"></div>
</div>
);
@abhishekjakhar
abhishekjakhar / index.js
Created April 30, 2019 17:29
index.js (Mocktail App)
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));
@abhishekjakhar
abhishekjakhar / App.js
Created April 30, 2019 16:17
updateMocktail Method
updateMocktail = mocktail => {
const newMocktail = mocktail;
this.setState(state => {
if (state.mocktail === newMocktail) {
return null;
} else {
return { mocktail };
}
})
}