I'm trying to work out how to call firebase functions from within a react component.
React component...
import React from 'react';
import './App.css';
import functions from '../functions/index'
function App() {
const callFirebaseFunction = event =>{
var output = functions.returnMessage()
console.log(output)
}
return(
<div>
<button onClick={event => callFirebaseFunction()}>call function button</button>
</div>
)
firebase functions index.js...
const functions = require('firebase-functions');
exports.returnMessage = functions.https.onCall((data, context) => {
return {
output: "the firebase function has been run"
}
});
Hopefully my code explains what i'm trying to do. Feel free to correct any other mistakes that i'm making in this very simple example.
The issue that i'm having is that I can't import anything to the component that isn't within the src folder and the firebase functions falls outside of this. I don't really want to eject anything as i'm assuming that there is a proper way for me to access my firebase functions and I simply can't find it.