socket.io使套接字提供程序TS友好

socket.io使套接字提供程序TS友好,socket.io,react-native-android,use-context,createcontext,Socket.io,React Native Android,Use Context,Createcontext,我正在创建一个聊天应用程序,我想为我的react本机应用程序使用一个套接字提供程序,但我无法获取我的代码,因为freindly正在那里使此代码不显示错误 import React, { useContext, useEffect, useState } from 'react'; import { View } from "react-native"; import io from 'socket.io-client'; const SocketContext = Rea

我正在创建一个聊天应用程序,我想为我的react本机应用程序使用一个套接字提供程序,但我无法获取我的代码,因为freindly正在那里使此代码不显示错误

import React, { useContext, useEffect, useState } from 'react';
import { View } from "react-native";
import io from 'socket.io-client';


const SocketContext = React.createContext()

export const useSocket = () => {
    return useContext(SocketContext)
}
export const SocketProvider = (id: any, children: any) => {
    const [socket, setSocket] = useState()
    useEffect(() => {
        const newSocket = io('myIP',
            { query: { id } })

        setSocket(newSocket)
        return () => {
            newSocket.close();
        }
    }, [id])
    return (

        <SocketContext.Provider value={socket}>
            {children}
        </SocketContext.Provider>
    );
}
import React,{useContext,useffect,useState}来自'React';
从“react native”导入{View};
从“socket.io客户端”导入io;
const SocketContext=React.createContext()
导出常量useSocket=()=>{
返回useContext(SocketContext)
}
export const SocketProvider=(id:any,children:any)=>{
const[socket,setSocket]=useState()
useffect(()=>{
const newSocket=io('myIP',
{查询:{id}})
setSocket(newSocket)
return()=>{
newSocket.close();
}
},[id])
返回(
{儿童}
);
}
createContext()= 应为1个参数,但得到0.ts(2554) index.d.ts(383,9):未提供“defaultValue”的参数

setSocket(newSocket)= “Socket”类型的参数不能分配给“SetStateAction”类型的参数。 类型“Socket”未提供与签名(prevState:undefined):undefined)匹配的项。ts(2345)