I have been implementing a server using the package available at https://github.com/futurepress/react-native-static-server. The server has two main functions, namely server.start()
to initiate the server and server.stop()
to terminate the server.
The method responsible for starting the server is _startServer()
. However, I am facing an issue on how to correctly pass the reference to the server to stop it using the _stopServer()
function.
export default class Foo extends Component {
_startServer = () => {
server.start()
.then((localServer) => {
this.setState({
serverRunning: true,
localServer: localServer
})
});
}
_stopServer = (refToServer) => {
refToServer.stop();
}
...
render() {
return (
<TouchableOpacity
onPress={() => this._startServer()} />
<TouchableOpacity
onPress={() => this._stopServer(??)} />
)
}
}