next.js getStaticProps返回null

egdjgwm8  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(144)

我在getStaticProps中有两个db查询,都正确返回值,但是当我返回props时,只有一个返回正确的数据,另一个将变为null。

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;

字符串

ndasle7k

ndasle7k1#

我一直在传递一个名为prop from _app的配置,它已经从getStaticProps传递过来。

相关问题