This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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" | |
/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RecoilRoot } from "recoil"; | |
function App() { | |
return ( | |
<RecoilRoot> | |
<CreateUser /> | |
<UsersList /> | |
</RecoilRoot> | |
); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRecoilValue } from "recoil"; | |
function UsersList() { | |
const users = useRecoilValue(usersState); | |
return ( | |
<ul> | |
{users.map((user) => ( | |
<li key={user.id}>{user.name}</li> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { atom } from "recoil"; | |
const usersState = atom({ | |
key: "usersState", | |
default: [] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore, applyMiddleware } from "redux"; | |
import thunk from "redux-thunk"; | |
import { Provider, connect } from "react-redux"; | |
const initialState = { | |
users: [], | |
loading: false | |
}; | |
const actionTypes = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { RecoilRoot, atom, useRecoilState, useRecoilValue } from "recoil"; | |
const usersState = atom({ | |
key: "usersState", | |
default: [] | |
}); | |
const loadingState = atom({ | |
key: "loadingState", | |
default: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import DataTable from "./components/DataTable"; | |
class App extends React.Component { | |
state = { | |
todos: [], | |
}; | |
componentDidMount() { | |
fetch("https://jsonplaceholder.typicode.com/todos") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
return ( | |
<table ref={(el) => (this.el = el)}> | |
<thead> | |
<tr> | |
<th>#</th> | |
<th>Title</th> | |
<th>Completed</th> | |
<th></th> | |
</tr> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidUpdate(prevProps) { | |
if (prevProps.children !== this.props.children) { | |
// update third-party library based on prop change | |
} | |
} |
NewerOlder