在ReactJS应用中使用Azure AI Immersive Reader遇BadArgument错误求助
解决Azure AI Immersive Reader在React中出现"Content must not be null"的问题
检查传入的Content结构有效性
调用ImmersiveReader.launchAsync时,必须确保content参数的chunks数组包含至少一个带有非空text字段的对象。空数组或text为空字符串都会触发该错误。正确的结构示例:const content = { chunks: [ { text: '待处理的目标文本', lang: 'zh' } ] };确保内容变量已正确初始化
如果内容来自组件状态或props,在调用启动函数前要先判断内容是否存在,避免传入初始的null或undefined。例如:const [targetText, setTargetText] = useState(''); const launchReader = async () => { if (!targetText.trim()) return; // 过滤空文本 // 此处添加获取token和subdomain的逻辑 await ImmersiveReader.launchAsync(token, subdomain, { chunks: [{ text: targetText, lang: 'zh' }] }); };排查参数传递错误
确认调用SDK时没有误将content参数传为null或undefined,检查变量命名、解构赋值是否正确,避免类似launchAsync(token, subdomain, null)这类错误写法。等待内容来源加载完成
如果内容来自异步请求(如API调用),要确保请求成功返回有效数据后再调用启动函数,避免在数据未加载完成时传入未初始化的内容。
内容的提问来源于stack exchange,提问作者AddyProg
相关产品推荐
相关产品推荐

