import moment from 'moment';
const datesArr = ['2020-03-01', '2020-01-10', '2020-02-07'];
const result = datesArr.sort((d1, d2) => moment(d1) - moment(d2));
console.log(result); // asc sort
.overflow-with-ellipsis { | |
white-space: nowrap; | |
overflow: hidden; | |
text-overflow: ellipsis; | |
width: 200px; /** width should be there for the traget or parent container */ | |
} |
// helper function to get all focusable elements in the context provided in arguments | |
function getFocusable(context = 'document') { | |
let focusable = Array.from(context.querySelectorAll('button, [href], select, textarea, input:not([type="hidden"]), [tabindex]:not([tabindex="-1"])')); | |
return focusable; | |
} | |
// get the first focusable element within a context | |
export function getFirstFocusable(context = 'document') { | |
let focusable = getFocusable(context); |
document.addEventListener('keyup', (event) => { | |
switch (event.keyCode) { | |
// escape | |
case 27: | |
// code to exit current component | |
break; | |
// enter || spacebar | |
case 13 || 32: | |
// submit or some action |
React recently introduced an experimental profiler API. This page gives instructions on how to use this API in a production release of your app.
Table of Contents
Profiling in production
// vendors | |
import styled from 'styled-components'; | |
// components | |
import LoadingSpinner from '../../../components/loading-spinner/loading-spinner'; | |
export const LoadingSpinnerStyled = styled(LoadingSpinner)` | |
margin: 20px; | |
`; |
import styled from 'styled-components'; | |
// components | |
import LoadingSpinner from '../../../components/loading-spinner/loading-spinner'; | |
export const LoadingSpinnerStyled = styled(LoadingSpinner)` | |
margin: 20px; | |
`; | |
LoadingSpinnerStyled.displayName = 'LoadingSpinnerStyled'; |
import { | |
LoadingSpinnerStyled, | |
ErrorStyled, | |
} from './user.styled'; | |
export class User extends Component { | |
render() { | |
const { fetching, userDetails, errorFlag } = this.props; | |
let content; | |
if(fetching) { |
Speaker Rider
by Tatiana Mac
Before I'll agree to a speaking event, I try to do as much research I can around the event to ensure it aligns with my ethos. I want to share this in case it's helpful to any other speakers.
function flattenArray(arr, res) { | |
let result = []; | |
for(let index = 0; index < arr.length; index++) { | |
const currentValue = arr[index]; | |
if(Array.isArray(currentValue)) { | |
result = [...result, ...(flattenArray(currentValue))]; | |
// we can also use concat method to achieve the same result | |
// result = result.concat(flattenArray(currentValue)); | |
} else { |