This file contains 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
// EXAMPLE WITH CONTEXT + REDUCER | |
import React, {useContext, useReducer} from 'react'; | |
const AppContext = React.createContext(null); | |
const ContextProvider = ({children}) => { | |
const reducer = (state, action) => { | |
switch (action.type) { |
This file contains 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
// EXAMPLE WITH CONTEXT | |
import React, {useContext, useState} from 'react'; | |
const AppContext = React.createContext(null); | |
const ContextProvider = ({children}) => { | |
const [counter, setCounter] = useState(0); | |
const contextValue = { | |
counter, |
This file contains 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 class="no-js" lang="" xmlns:x-bind="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta charset="utf-8"> | |
<title>AlpineJS Todo</title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.js" defer></script> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> |
This file contains 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
program Todo; | |
{$mode objfpc} | |
uses | |
JS, Classes, SysUtils, Web; | |
type | |
task = record | |
name: String; |
This file contains 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
<div x-data="{password: ''}"> | |
<input x-model="password" placeholder="Enter your password" /> | |
<p x-show="password === 'abacaba'">Access granted</p> | |
<p x-show="password !== 'abacaba'">Access denied</p> | |
</div> |
This file contains 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, {useState} from 'react'; | |
function App() { | |
const [password, setPassword] = useState(''); | |
return ( | |
<> | |
<input | |
placeholder='Enter the password' | |
value={password} |
This file contains 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
<div x-init="console.log('this runs when component is mounted')"> | |
<button @click="console.log('this runs when button is clicked')"> | |
Click me | |
</button> | |
</div> |
This file contains 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, {useEffect} from 'react'; | |
function App() { | |
useEffect(() => { | |
console.log('this will output when app loads'); | |
}, []); | |
return ( | |
<button onClick={console.log('this will output when button is clicked')}> | |
Click me |
This file contains 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
<div x-data="{name: ''}"> | |
<input x-model="name" /> | |
<p>Hello, <span x-text="name" /></p> | |
</div> |
This file contains 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, {useState} from 'react'; | |
function App() { | |
const [name, setName] = useState(''); | |
return ( | |
<> | |
<input value={name} onChange={e => setName(e.target.value)} /> | |
<p>Hello, {name}</> | |
</> |