2021-05-11 14:37:15 +00:00
|
|
|
import { createContext } from "react"
|
2021-04-26 16:36:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A context containing an object with the following values:
|
|
|
|
* - `server`: the base URL of the currently active backend server
|
|
|
|
* - `setServer`: a function to change `server`
|
|
|
|
* - `fetchData`: a function to fetch JSON data from the backend server
|
|
|
|
*
|
|
|
|
* If accessed from outside a provider, the values will be:
|
|
|
|
* - `server`: `null`
|
|
|
|
* - `setServer`: a function showing an error in the console
|
|
|
|
* - `fetchData`: another function showing an error in the console
|
|
|
|
*
|
|
|
|
* @type {React.Context}
|
|
|
|
*/
|
|
|
|
const ContextServer = createContext({
|
|
|
|
server: null,
|
2021-05-14 09:31:14 +00:00
|
|
|
setServer: () => console.error("Provato ad eseguire setServer mentre fuori da un ContextServer.Provider!"),
|
|
|
|
fetchData: () => console.error("Provato ad eseguire fetchData mentre fuori da un ContextServer.Provider!"),
|
2021-04-26 16:36:41 +00:00
|
|
|
})
|
|
|
|
export default ContextServer
|