Skip to content

Instantly share code, notes, and snippets.

@isabellachen
isabellachen / uninstall-reinstall-update-npm-package.md
Created January 27, 2020 09:54
Uninstall and reinstall npm packages

Update the version from latest to beta version.

npm uninstall react-simple-maps
npm i -S npm i @types/react-simple-maps

Dont't forget to update types!

npm uninstall @types/react-simple-maps
@isabellachen
isabellachen / typings.d.ts
Created January 23, 2020 16:42
Export typings for modules that have no typings
declare module 'react-metismenu' {
const mentisMenu: any;
export default mentisMenu;
}
declare module 'wsdm-tooltip' {
const wsdmTooltip: any;
export default wsdmTooltip;
}
@isabellachen
isabellachen / layout.html
Created January 23, 2020 12:24
Content of nested flex child to constrain to calculated width of the child
<div class="flex-parent has-child">
<div class="flex-child long-and-truncated-with-child-corrected">
<h2>3. This is a long string that is OK to truncate please and thank you</h2>
</div>
<div class="flex-child short-and-fixed">
<div></div>
<div></div>
<div></div>
@isabellachen
isabellachen / declare-event-types-form-handlers.js
Created November 20, 2019 11:43
React Typescript with Event types of Form Handlers
// With Bootstrap
const onPageNameChange = (e: React.FormEvent<FormControl & FormControlProps>) => {
const value = (e.target as HTMLInputElement).value;
updatePageName(value);
};
const onDataSourceChange = (e: React.FormEvent<FormControl & FormControlProps>) => {
const value = (e.target as HTMLSelectElement).value;
updateChosenDataSource(value);
};
@isabellachen
isabellachen / react-ts-router-translation-props.js
Created November 19, 2019 15:53
Extend component props with props from react router and react i18n with react typescript
import { WithTranslation, withTranslation, useTranslation } from 'react-i18next';
import { RouteComponentProps, withRouter } from 'react-router-dom';
export type MyDemoProps = {} & RouteComponentProps & WithTranslation;
function MyDemoComponent({
history,
t,
}: MyDemoProps) {
const [t] = useTranslation(); //alternatively, import translation function directly into component
@isabellachen
isabellachen / abort-request-on-navigate.js
Created November 12, 2019 10:02
Abort request on navigate in React
import { cid, useInject } from 'inversify-hooks';
import React, { Suspense, useEffect } from 'react';
import { Redirect, Route, Switch, useHistory } from 'react-router-dom';
import { exampleModule } from './example';
import { IHttpService } from './shared';
import { styleGuideModule } from './style-guide';
let didTheUserNavigatedForTheFirstTime = false;
export default function AppRouter() {
const history = useHistory();
@isabellachen
isabellachen / react-typescript.md
Last active October 25, 2019 10:00
React Typescript: Common Troubles

When dealing with return data from React events, you might need to cast the data back to the original.

<InputMultiSelect
  value={chosenDataStorageUnit.map(f => f.value)}
/>
@isabellachen
isabellachen / center-a-div.css
Last active October 21, 2019 16:39
Centering an element without flexbox
/*Flexbox should be the answer. But this is for those times flexbox does not suit your needs*/
.graphic-wrapper {
position: relative;
}
.graphic {
position: absolute;
top: 50%;
left: 50%;
@isabellachen
isabellachen / add-icomoon.md
Last active October 16, 2019 11:15
Add fonts from icomoon to project

Create or add fonts

  • Import selection.json file into icomoon app.
  • Import the new svg icon.
  • Export as font.
  • Unpack and add all the selection.json, .eot, .svg, .ttf and .woff files to the project, replacing the existing files if there are any.

Register the font with @font-face

  • Look for the _icon.scss partial file
  • You can register the unicode as a variable and use it, or add it directly to the css.
@isabellachen
isabellachen / PHP-basics.md
Last active October 20, 2019 16:20
PHP basics for Javascript Programmers

PHP Web Server

Chucks out interactive webpages. Kinda like the Webpack server. Both environments are on Repl.it and come with basic examples, check it out.

PHP CLI

Like the JavaScript console in DevTools.

Semicolons

PHP requires each statement to be terminated with a semi-colon.