From 64bdef3439afa0f54c09cfa85bf4453f28ed7e3e Mon Sep 17 00:00:00 2001 From: Pratikshaekbote <80769944+Pratikshaekbote@users.noreply.github.com> Date: Fri, 28 Oct 2022 22:45:46 +0530 Subject: [PATCH 1/2] Modified Markdown.md --- CheatSheets/markdown-cheatsheet.md | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/CheatSheets/markdown-cheatsheet.md b/CheatSheets/markdown-cheatsheet.md index d0df5e0..c66facc 100644 --- a/CheatSheets/markdown-cheatsheet.md +++ b/CheatSheets/markdown-cheatsheet.md @@ -9,6 +9,9 @@ created: 2022-10-18 - [Markdown CheatSheet for Developers](#markdown-cheatsheet-for-developers) - [Basic Syntax](#basic-syntax) - [Extended Syntax](#extended-syntax) + - [Emphasis](#emphasis) + - [Lists](#lists) + - [Images](#Images) # Markdown CheatSheet for Developers @@ -42,4 +45,46 @@ created: 2022-10-18 | `\| col1 \| col2 \|`
`\|------\|------\| `
`\|data1 \|data2 \|`
`\|data3 \|data4 \|` | Table | | `Here's a sentence with a footnote. [^1] `
`[^1]: This is the footnote.` | Footnote | +## Emphasis +Emphasis, aka italics, with *asterisks* or _underscores_. + +Strong emphasis, aka bold, with **asterisks** or __underscores__. + +Combined emphasis with **asterisks and _underscores_**. + +Strikethrough uses two tildes. ~~Scratch this.~~ + +## Lists + +1. First ordered list item +2. Another item +⋅⋅* Unordered sub-list. +1. Actual numbers don't matter, just that it's a number +⋅⋅1. Ordered sub-list +4. And another item. + +⋅⋅⋅You can have properly indented paragraphs within list items. Notice the blank line above, and the leading spaces (at least one, but we'll use three here to also align the raw Markdown). + +⋅⋅⋅To have a line break without a paragraph, you will need to use two trailing spaces.⋅⋅ +⋅⋅⋅Note that this line is separate, but within the same paragraph.⋅⋅ +⋅⋅⋅(This is contrary to the typical GFM line break behaviour, where trailing spaces are not required.) + +* Unordered list can use asterisks +- Or minuses ++ Or pluses + +##Images + +Here's our logo (hover to see the title text): + +Inline-style: +![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 1") + +Reference-style: +![alt text][logo] + +[logo]: https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png "Logo Title Text 2" + + + **[🔼Back to Top](#table-of-contents)** From e4e836e75beb4c9e9c6808f1f27bf7c65e830418 Mon Sep 17 00:00:00 2001 From: Pratikshaekbote <80769944+Pratikshaekbote@users.noreply.github.com> Date: Fri, 28 Oct 2022 23:27:08 +0530 Subject: [PATCH 2/2] Added Cheat sheet for React --- CheatSheets/React-Cheatsheet.md | 698 ++++++++++++++++++++++++++++++++ 1 file changed, 698 insertions(+) create mode 100644 CheatSheets/React-Cheatsheet.md diff --git a/CheatSheets/React-Cheatsheet.md b/CheatSheets/React-Cheatsheet.md new file mode 100644 index 0000000..9ac2378 --- /dev/null +++ b/CheatSheets/React-Cheatsheet.md @@ -0,0 +1,698 @@ +# 📚 React Cheat Sheet +This repository is a cheat sheet to React for daily use. It contain a lot of snippets from my own use / official documentation and i'll improve it soon ! +It's made for people like me who like to continue have a overview of some snippets. + +## Table of Contents + +1. **[React](#1---react)** +2. **[Redux](#2---redux)** + +## 1 - React +### Use React +```javascript +// Import React and ReactDOM +import React from 'react' +import ReactDOM from 'react-dom' +``` + +```javascript +// Render JSX into a DOM element +ReactDOM.render( +

Hello, world!

, + document.getElementById('root') +); +``` + +```javascript +// Render Component into a DOM element +ReactDOM.render( + , + document.getElementById('root') +); +``` +**[⬆ Go to top](#table-of-contents)** + +### JSX +```javascript +// JSX produce React Element +const item =

My JSX Element

; +``` + +```javascript +// Use curly braces to embed some Javascript +const item =
{getContent()}
; +``` + +```javascript +// Use camelCase for attribute name +const item =
; +``` + +```javascript +// Use curly braces to embed some Javascript +const item = ; +``` + +```javascript +// Self close if tag is empty +const item =
; +``` +**[⬆ Go to top](#table-of-contents)** + +### Components +```javascript +// Stateless Functional Component +function Heading(props) { + return

{props.title}

; +} +``` + +```javascript +// Stateless Functional Component (with arrow function) +const Heading = (props) => { + return

{props.title}

; +} +``` + +```javascript +// ES6 Class Component, can have states +class Heading extends React.Component { + render() { + return

{this.props.title}

; + } +} +``` + +```javascript +// Always start component names with capital + +``` +**[⬆ Go to top](#table-of-contents)** + +### Render +```javascript +// Return React Element +render() { + return
Example of return
+} +``` + +```javascript +// Return Another Component +render() { + return +} +``` + +```javascript +// Return String +render() { + return 'Return a string works!' +} +``` + +```javascript +// Return Numbers (rendered as text node) +render() { + return 100 +} +``` + +```javascript +// Return nothing +render() { + return null +} +``` +**[⬆ Go to top](#table-of-contents)** + +### Component Lifecycle +```javascript +componentWillMount() { + +} +``` + +```javascript +componentDidMount() { + // Call after the component output has been rendered in the DOM +} +``` + +```javascript +componentWillReceiveProps() { + +} +``` + +```javascript +shouldComponentUpdate() { + +} +``` + +```javascript +componentWillUpdate() { + +} +``` + +```javascript +componentDidUpdate() { + +} +``` + +```javascript +componentWillUnmount() { + +} +``` + +```javascript +componentDidCatch() { + +} +``` +**[⬆ Go to top](#table-of-contents)** + +### Props (Properties) +Props are immutable. + +```javascript +// Component with a single valid argument : props +function Heading(props) { + return

{props.title}

; +} +``` +**[⬆ Go to top](#table-of-contents)** + +### State +State are locals and fully controlled by the component itself. + +```javascript +// Update state with setState, except in constructor +this.setState({ + title: 'Updated title', +}); +``` + +```javascript +// Set state with previous state +this.setState((prevState, props) => { + return {count: prevState.count + 1}; +}); +``` + +```javascript +// Declare initial state in constructor +class Heading extends React.Component { + constructor(props) { + super(props); + this.state = {title: 'My title'}; + } +} +``` + +```javascript +// Do not update state directly +this.state.title = 'Hello'; +``` + +```javascript +// Lifting state up to share state between component +class Wrapper extends React.Component { + constructor(props) { + super(props); + this.handleInputChange = this.handleInputChange.bind(this); + this.state = {value: ''}; + } + + handleInputChange(value) { + this.setState({value}); + } + render() { + const value = this.state.value; + return ( + + ); + } +} + +class Input extends React.Component { + constructor(props) { + super(props); + this.handleChange = this.handleChange.bind(this); + } + + handleChange(e) { + this.props.onInputChange(e.target.value); + } + + render() { + const value = this.props.value; + return ; + } +} +``` +**[⬆ Go to top](#table-of-contents)** + +### Handling Event +```javascript +// React Event are in camelCase + +``` + +```javascript +// Use preventDefault instead of return false +function handleClick(e) { + e.preventDefault(); +} + +``` + +```javascript +// Bind this to use it in the callback +constructor(props) { + super(props); + this.handleClick = this.handleClick.bind(this); +} +``` + +```javascript +// Pass data to callback + + +``` +**[⬆ Go to top](#table-of-contents)** + +### Conditional Rendering +```javascript +// Using if operator with props +function Heading(props) { + const isHome = props.isHome; + if (isHome) { + return ; + } + return ; +} +``` + +```javascript +// Using if operator with state +render() { + const isHome = this.state.isHome; + let heading = null; + if (isHome) { + heading = ; + } else { + heading = ; + } + + return ( +
+ {heading} +
+ ); +} +``` + +```javascript +// Using ternary operator +
+ {isHome ? : } +
+``` + +```javascript +// Using logical operator +
+ {messages.length > 0 && +

+ You have messages +

+ } +
+``` + +```javascript +// Prevent component from rendering +function Modal(props) { + if (!props.isShow) { + return null; + } + + return ( +
+ Modal +
+ ); +} +``` + +**[⬆ Go to top](#table-of-contents)** + +### Portal +```javascript +import { createPortal } from "react-dom"; + +class MyPortalComponent extends React.Component { + render() { + return createPortal( + this.props.children, + document.getElementById("node"), + ); + } +} +``` +**[⬆ Go to top](#table-of-contents)** + +### Fragment +```javascript +const Fragment = React.Fragment; + +render() { + return ( + + Some text. +

A heading

+ Even more text. +
+ ); +} +``` + +```javascript +render() { + return ( + + Some text. +

A heading

+ Even more text. + + ); +} +``` + +```javascript +render() { + return ( + <> + + + + ); +} +``` +**[⬆ Go to top](#table-of-contents)** + +### Forms + +#### Controlled Components +```javascript +// In controlled component, each state mutation have an handler function +class Form extends React.Component { + constructor(props) { + super(props); + this.state = {value: ''}; + + this.handleChange = this.handleChange.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); + } + + handleChange(e) { + this.setState({value: e.target.value}); + } + + handleSubmit(e) { + alert('Submitted value: ' + this.state.value); + e.preventDefault(); + } + + render() { + return ( +
+ + +
+ ); + } +} +``` + +```javascript +// Force to uppercase in handler +handleChange(e) { + this.setState({value: e.target.value.toUpperCase()}); +} +``` + +```javascript +//