Skip to content

Instantly share code, notes, and snippets.

View bewarusman's full-sized avatar
🎯
Focusing

Bewar Salah bewarusman

🎯
Focusing
View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Online Text Editor</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
/>
import { useState } from 'react';
import { useRecoilState } from "recoil";
function CreateUser() {
const [, setUsers] = useRecoilState(usersState);
const [name, setName] = useState('');
function handleSubmit(e) {
e.preventDefault();
setUsers(users => setUsers([...users, {
import { RecoilRoot } from "recoil";
function App() {
return (
<RecoilRoot>
<CreateUser />
<UsersList />
</RecoilRoot>
);
}
import { useRecoilValue } from "recoil";
function UsersList() {
const users = useRecoilValue(usersState);
return (
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
import { atom } from "recoil";
const usersState = atom({
key: "usersState",
default: []
});
import { createStore, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import { Provider, connect } from "react-redux";
const initialState = {
users: [],
loading: false
};
const actionTypes = {
import { RecoilRoot, atom, useRecoilState, useRecoilValue } from "recoil";
const usersState = atom({
key: "usersState",
default: []
});
const loadingState = atom({
key: "loadingState",
default: false
import React from "react";
import DataTable from "./components/DataTable";
class App extends React.Component {
state = {
todos: [],
};
componentDidMount() {
fetch("https://jsonplaceholder.typicode.com/todos")
render() {
return (
<table ref={(el) => (this.el = el)}>
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Completed</th>
<th></th>
</tr>
componentDidUpdate(prevProps) {
if (prevProps.children !== this.props.children) {
// update third-party library based on prop change
}
}