Skip to content

Instantly share code, notes, and snippets.

View tkssharma's full-sized avatar
🎯
only JS

codewithtkssharma tkssharma

🎯
only JS
View GitHub Profile
{
arrowParens: 'avoid',
bracketSpacing: true,
htmlWhitespaceSensitivity: 'css',
jsxBracketSameLine: false,
printWidth: 80,
proseWrap: 'preserve',
requirePragma: false,
semi: true,
singleQuote: true,
@Component({
selector: 'app-books',
templateUrl: './books.component.html'
})
export class BooksComponent implements OnDestroy, OnInit {
private ngUnsubscribe = new Subject();
constructor(private booksService: BookService) { }
ngOnInit() {
<div class="container">
<div class="block">
<h1>List of users</h1>
<ul *ngIf="userWithPost$ | async as userList">
<li *ngFor="let user of userList">
<a href="#" (click)="selectUser(user.id)">{{user.username}}</a>
</li>
</ul>
</div>
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent {
user$ = this.usersService.user$;
userWithPost$ = this.usersService.userWithPost$;
selectedUser$ = this.usersService.selectedUser$;
@Injectable({
providedIn: 'root'
})
export class UsersService {
constructor(private http: HttpClient, private postsService: PostsService) { }
private userSelectedAction = new Subject<number>();
private usersUrl = 'https://jsonplaceholder.typicode.com/users';
user$ = this.http.get<Users>(this.usersUrl).pipe(shareReplay());
userWithPost$ = combineLatest(
import React, { useState, useMemo } from "react";
const fibonacci = n => {
if (n <= 1) {
return 1;
}
return fibonacci(n - 1) + fibonacci(n - 2);
};
const MemoComponent = () => {
function LocalStorageHook() {
const [count, setCount] = useState(() => {
let value;
try {
value = JSON.parse(
window.locastorage.getItem('count') || '0'
)
} catch (e) {
import React from 'react';
import gql from 'graphql-tag';
import { Query } from 'react-apollo';
import SpacexComponent from './Space';
import Mock from './Space/mock';
const GET_SPACEX_DATA = gql`
{
launchesPast(limit: 10) {
mission_name
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { ApolloLink, concat } from 'apollo-link';
const httpLink = new HttpLink({ uri: '/graphql' });
// registering middlewares [authMiddleware, otherMiddleware ]
const authMiddleware = new ApolloLink((operation, forward) => {
// add the authorization to the headers
operation.setContext({
headers: {
authorization: localStorage.getItem('token') || null,
import React from "react";
import ReactDOM from "react-dom";
const ToDoContext = React.createContext();
class ToDoList extends React.Component {
state = {
list: [],
todo: ""
};
createNewToDoItem = () => {
this.setState(({ list, todo }) => ({