HTML标签与React-Native中的内容一起呈现使用WebView尝试过,但是会引发错误

问题描述

我正在将expo用于本机应用程序。我在React-Native App中进行API调用后呈现内容。但是所有HTML标记也都已呈现。这是我没有webview的初始代码:

import React,{ useState,useEffect } from 'react';
import { View,Text,StyleSheet,ScrollView } from 'react-native';

const App = () => {
  const [posts,setPosts] = useState([]);

  useEffect(() => {
    fetch("http://172.27.13.38/api/1?position=1.1")
      .then((response) => response.json())
      .then((json) => setPosts(json.field_gita_2_text.content))
      .catch((error) => console.log(error));
  });

  return (
    <View style={styles.container}>
      <ScrollView>{posts.length ? <Text>{posts}</Text> : null}</ScrollView>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    padding: 80,justifyContent: 'center',alignItems: 'center',},});

export default App;

这会用html标签呈现我的内容。

enter image description here

然后我尝试使用WebView呈现html:

{posts.length ? <WebView  source={{html : {posts}}} : null/>} 

但这会引发错误:无法将HTML的值从ReadableNativeMap转换为字符串

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)