console log said āquery find undefinedā
You have no errors in your browser console?
Yea but I always have errors, idk if this has anything to do with it:
Warning: Functions are not valid as a React child. This may happen if you return a Component instead of <Component /> from render. Or maybe you meant to call this function rather than return it.
Also the server logs show it returned perfectly just now
My cloud logs only show when I call results(), if I dont add parentheses nothing happensā¦ Either way undefined on front end and browser console
that is probably because you defined result as a function
you could return something in that function maybe
I cant even render the page anymore, computer is getting hot too
Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
ok, probably it was not a good idea, it looks like you got an infinite loop now
const results = async () => { return(await Moralis.Cloud.run("searchResults", params))}
Do you know why nothing is returning?
It looks like this works fine for me in a react app:
import { useMoralis } from "react-moralis";
function App() {
const { Moralis } = useMoralis();
const x = async () => {
try {
const x3 = await Moralis.Cloud.run("test_result");
console.log("x3", x3);
} catch (e) {
console.log(e);
}
};
return (
<div>
<p>
<button onClick={x}> test button</button>
</p>
</div>
);
}
export default App;
I copy and pasted the exact thing but replaced console.log with returnā¦didnāt get anything, not even an error was returnedā¦ Also as you see Iām in a class component so I canāt useMoralis()
This works too:
const Moralis = require("moralis");
function App2() {
const x = async () => {
try {
const x3 = await Moralis.Cloud.run("test_result");
console.log("x3", x3);
} catch (e) {
console.log(e);
}
};
return (
<div>
<p>
<button onClick={x}> test button 2</button>
</p>
</div>
);
}
export default App2;
If you let that console.log and look in the console you should see the output
class Navy extends Component {
constructor(props) {
super(props);
this.state = {
showsearch: false,
searchcontent: null
}
this.openSearch = this.openSearch.bind(this);
this.closeSearch = this.closeSearch.bind(this);
this.handleChange = this.handleChange.bind(this)
}
openSearch() {
this.setState({ showsearch: true });
}
closeSearch() {
let vm = this;
setTimeout(() => {
vm.setState({ showsearch: false });
}, 100);
}
handleChange(e) {
var value = e.target.value;
this.setState({searchcontent: value});
}
render() {
const Moralis = require('moralis')
const params = { value: this.state.searchcontent};
const results = async () => {
try {
const x3 = await Moralis.Cloud.run("searchResults", params);
return("x3", x3);
} catch (e) {
return(e);
}
};
return(
<Modal show={this.state.showsearch} onHide={this.closeSearch} size='lg' centered >
<Modal.Header >
<Modal.Title>Search</Modal.Title>
</Modal.Header>
<Modal.Body>
Search Results #: {results.length} <br/>
Result (JSON): {JSON.stringify(results)} <br/>
Result: {results}
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={this.closeSearch}>
Close
</Button>
</Modal.Footer>
</Modal>
)}}
literally nothing is returningā¦ no error, not even the āx3ā string
I switched my button to onClick={x} and it did console.log the arrayā¦ do you think thereās a reason it wonāt return on the modal? not even results.length
@cryptokid noticed the right thing:
That is probably because you defined result as a function
you could return something in that function maybe
Where is that? is that app id or server url?
You have inserted a function to render, not its result
this is my current code though:
const Moralis = require('moralis')
const params = { value: this.state.searchcontent};
const results = async () => {
try {
const x3 = await Moralis.Cloud.run("searchResults", params);
return(x3);
} catch (e) {
return(e);
}
};
I made it a function because so far Iāve had no other option when using await, Iād get errors