I'm experiencing an issue with my getStaticProps where only one of the two db queries is returning correct data while the other returns null. What could be causing this problem?
const Dash = (props) => {
const config = props.config;
useEffect(() => {
console.log("config", props.config) /* returns null*/
}, []);
return(/*...*/)
}
export const getStaticProps = async (ctx) => {
const dbConnection: mysql.Connection = await mysql.createConnection({
host: process.env.DB_HOST,
database: process.env.DB_DATABASE,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
socketPath: process.env.DB_SOCKET
})
const newsRes = dbConnection.query(`SELECT * FROM ucp_news`)
const configRes = dbConnection.query(`SELECT * FROM ucp_config`)
const responses = await Promise.all([newsRes, configRes])
console.log(responses[1][0][0]) /* returns config value correctly */
dbConnection.destroy()
return {
props: {
news: responses[0][0], /* returns correct value */
config: responses[1][0][0] /* returns null instead of config value */
}
}
}
export default Dash;