title: Can't update state in React Context using function
body: <p>I currently have two contexts - GalleryContext &amp; AdminContext</p>
  
  <p>In AdminContext, whenever I fire off handleSendImage(), I am trying to call a function (getGallery()) from GalleryContext which updates the gallery state in GalleryContext.</p>
  
  <p>However, I am receiving this error:
  Unhandled Rejection (TypeError): this.setState is not a function</p>
  
  <p>Could anyone please advise me on how to fix this? Much appreciated in advance!</p>
  
  <p>Here's my code:</p>
  
  <p>GalleryContext:</p>
  
  <pre><code>class GalleryProvider extends Component {
    state = {
      gallery: []
    };
    getGallery() {
      let database = firebase
        .database()
        .ref("/gallery/")
        .once("value")
        .then(images =&gt; {
          console.log(images.val());
          this.setState(
            {
              gallery: images.val()
            },
            () =&gt; {}
          );
        });
    }
    componentDidMount() {
      this.getGallery();
    }
    render() {
      return (
        &lt;GalleryContext.Provider
          value={{
            ...this.state,
            getGallery: this.getGallery
          }}&gt;
          {this.props.children}
        &lt;/GalleryContext.Provider&gt;
      );
    }
  }
  </code></pre>
  
  <p>AdminContext.js</p>
  
  <pre><code>class AdminProvider extends Component {
    static contextType = GalleryContext;
    state = {
      upload_image: null,
      gallery_title: null,
      gallery_description: null,
      gallery_filename: null,
      progress: null
    };
    handleSendImage = (event, gallery, user) =&gt; {
      event.preventDefault();
      const { upload_image } = this.state;
      firebase
        .storage()
        .ref(`images/${upload_image.name}`)
        .put(upload_image)
        .on(
          "state_changed",
          snapshot =&gt; {
            // progrss function ....
            const progress = Math.round(
              (snapshot.bytesTransferred / snapshot.totalBytes) * 100
            );
            this.setState({
              progress
            });
          },
          error =&gt; {
            // error function ....
            console.log(error);
          },
          () =&gt; {
            // complete function ....
            firebase
              .storage()
              .ref("images")
              .child(upload_image.name)
              .getDownloadURL()
              .then(url =&gt; {
                const newImage = {
                  description: this.state.gallery_description,
                  download_url: url,
                  file_name: this.state.gallery_filename,
                  id: gallery.length,
                  uploader_uid: user.uid
                };
                firebase
                  .database()
                  .ref("/gallery/")
                  .child(gallery.length)
                  .set(newImage)
                  .then(() =&gt; {
                    this.context.getGallery();
                  })
                  .catch(error =&gt; {
                    console.log(error);
                  });
              });
          }
        );
    };
    render() {
      return (
        &lt;AdminContext.Provider
          value={{
            ...this.state
            handleSendImage: this.handleSendImage
          }}&gt;
          {this.props.children}
        &lt;/AdminContext.Provider&gt;
      );
    }
  }
  </code></pre>