credentials: include
const [currentUser, setCurrentUser] = useState<string | null>(null)
<AuthContext.Provider value={[currentUser, setCurrentUser]}>
setCurrentUser('data.token')
null
или string
, но все равно ругаетсяCannot invoke an object which is possibly 'null'.ts(2721)
const setCurrentUser: React.Dispatch<React.SetStateAction<string | null>> | null
import { createContext, Dispatch, SetStateAction } from 'react'
export const AuthContext = createContext<[string | null, Dispatch<SetStateAction<string>> | null]>([null, null])
setCurrentUser
выдает ошибкуexport function App() {
const [currentUser, setCurrentUser] = useState<string | null>(null)
return <>
<AuthContext.Provider value={[currentUser, setCurrentUser]}>
</AuthContext.Provider>
</>
}
Type 'Dispatch<SetStateAction<string | null>>' is not assignable to type 'Dispatch<SetStateAction<string>>'.
Type 'SetStateAction<string>' is not assignable to type 'SetStateAction<string | null>'.
Type '(prevState: string) => string' is not assignable to type 'SetStateAction<string | null>'.
Type '(prevState: string) => string' is not assignable to type '(prevState: string | null) => string | null'.
Types of parameters 'prevState' and 'prevState' are incompatible.
Type 'string | null' is not assignable to type 'string'.
Type 'null' is not assignable to type 'string'
import { createContext, Dispatch, SetStateAction } from 'react'
export const AuthContext = createContext<[string, Dispatch<SetStateAction<string>>]>(['', ''])
Type 'string' is not assignable to type 'Dispatch<SetStateAction<string>>'.
const [currentUser, setCurrentUser] = useContext(AuthContext)
Type '{}' must have a '[Symbol.iterator]()' method that returns an iterator.ts(2488)
const currentUser: any
const {currentUser, setCurrentUser} = useContext(AuthContext)
Property 'currentUser' does not exist on type '{}'.ts(2339)
const currentUser: any
export function App() {
const [currentUser, setCurrentUser] = useState(null)
return <>
<AuthContext.Provider value={currentUser, setCurrentUser}>
<Header />
<Form />
</AuthContext.Provider>
</>
}
<AuthContext.Provider value={currentUser, setCurrentUser}>
JSX expressions may not use the comma operator. Did you mean to write an array?ts(18007)
const setCurrentUser: React.Dispatch<React.SetStateAction<null>>
export function Form() {
const [currentUser, setCurrentUser] = useContext(AuthContext)
}
Type '{}' must have a '[Symbol.iterator]()' method that returns an iterator.ts(2488)
'setCurrentUser' is declared but its value is never read.ts(6133)
const setCurrentUser: any
child
, что данный объект существует, но те свойства pid
, которые я в нем могу найти, они не те, которыми можно его остановить через process.kill(pid)
import { spawn } from 'child_process'
const child = spawn('npm', ['start'], {cwd: '../default'})
child.stdout.on('data', (data) => {
data = data.toString()
console.log('data:', data)
})
child.on('close', (code) => {
console.log('close spawn process')
})
process.on('SIGHUP', () => {
console.log('process sighup')
})
process.on('error', err => {
console.log('process error', err.message)
})
function stopChild() {
console.log('stopd child')
child.kill()
}
// Имитирую событие, что через 3 сек. к нам придет запрос на остановку запущенного процесса.
setTimeout(() => {
stopChild() - так не остановит процесс
}, 3000)
// child.kill() - так остановит процесс
// Сервер, который будет принимать запросы и по ним начнет запускать или останавливать приложения.
// Для тестирования запущен обычный сервер, чтобы скрипт не остановился.
import http from 'http'
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
Ведь кто-то может ввести чужую почту, а запись после будет висеть в бд
Или, если кто-то будет спамить регистрации несуществующими почтами?