Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

<Text> can't have any children except <Text>, <Image> or raw strings #1

Open
xcplus opened this issue Apr 25, 2016 · 4 comments
Open

Comments

@xcplus
Copy link
Contributor

xcplus commented Apr 25, 2016

I use react-native 0.24.1 version, the link and image tag are not display

@Thomas101
Copy link
Owner

Hi, Image support has been added in the latest version. What html are you trying to render to get this error?

@xcplus
Copy link
Contributor Author

xcplus commented Apr 28, 2016

if i set the html value:

html =  `<p>N+1 查询是大家经常碰到要去消灭的东西. 常用的方法就是使用 #includes/joins/eager_load 等方法, 在查询数据集的时候通知ORM去将关联数据用某种方式先预载出来.<br>
但是开发时老要想着这件事还是比较烦人的. 最近在用 GraphQL 重写一个后台服务碰到比较头疼的问题. 在写API的时候, 每个接口返回的数据都是非常确定的, 所以可以事先确定什么地方需要进行 eager loading. GraphQL 将组织查询结果的权利交给了前端. 这时候后端就无法在编写代码时就确定要 eager load 哪些关系了.<br>
在 ActiveRecord 的世界中有一个很出色的 gem <a href="https://github.com/salsify/goldiloader" target="_blank">Goldiloader</a>. 可以在代码执行中根据对关系的访问来触发 eager_load. 找了很久, 在 Mongoid 社区似乎还没有一个这样的 gem. 于是只能自己去实现类似的功能.</p>
<h2 id="功能">功能</h2>
<p>当数据集合里的第一次访问某个记录的引用关系时, 在整个数据集中 eager load 这个关系. 目前支持:</p>

<ul>
<li>has_one</li>
<li>has_many</li>
<li>belongs_to</li>
<li>has_and_belongs_to_many</li>
</ul>
<h2 id="安装">安装</h2>
<p>在Gemfile中添加</p>
<pre class="highlight ruby"><code><span class="n">gem</span> <span class="s1">'mongoload'</span></code></pre>

<p>或是通过 gem 命令安装</p>
<pre class="highlight shell"><code>gem install mongoload</code></pre>
<h2 id="支持版本">支持版本</h2>
<ul>
<li>ruby &gt;~ 2.1 (用到 Module#prepend)</li>
<li>mongoid &gt;~ 5.0
另外支持 github.com/mongodb/mongoid/tree/master 分支中的 mongoid 6.0.0, 由于mongoid 6.0.0 依赖 ActiveModel 5.0.0, 因此需要 ruby &gt;= 2.2.2</li>
</ul>
<h2 id="Github">Github</h2>
<p><a href="https://github.com/karloku/mongoload" target="_blank">Mongoload</a></p>`

then i add the code like this:

      <HTML
        html={html}
        onLinkPress={(evt, href) => console.log(href)} />

it will show the error like:

  <Text> can't have any children except <Text>, <Image> or raw strings

also warning:

  Warning: Failed propType: invalid props.style key 'fontSize' supplied to 'View'.
  Warning:  Failed propType: invalid props.style key 'fontSize' supplied to 'RCTView'.

but when i add code :

  const renderers = {
          img: (htmlAttribs, style, children, passProps) => {
              return (<Image source={{uri: htmlAttribs.src, width: width, height: height}} style={style} {...passProps} />)
          }
      }

  renderers={renderers}

it show me:

  Possible Unhandled Promise Rejection (id:0):
  Objects are not valid as a React child (found: object with keys {img}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `View`.
Invariant Violation: Objects are not valid as a React child (found: object with keys {img}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `View`.

@Thomas101
Copy link
Owner

Hi, I've the html you're trying to use and patched the library. It should work with version 1.0.4

@xcplus
Copy link
Contributor Author

xcplus commented Apr 29, 2016

thank you very much!!!
Today i have some issues:
1、

You are trying to nest a non-text HTML element inside a text element.
The following nodes can only be rendered within themselves and not within text nodes:
div
ol
ul

2、when i add:

const renderers = {
      img: (htmlAttribs, children, passProps) => {
        return (
          <Image
            source={{uri: htmlAttribs.src, width: 100, height: 100}}
            style={passProps.htmlStyles.img}
            {...passProps} />)
      }
    }

renderers={renderers}

will get issue:

Possible Unhandled Promise Rejection (id: 0):
Objects are not valid as a React child (found: object with keys {img})

3、 i add styles code:

    const topicStyles = {
      h1: {width: 24}
    }

          <HTML
            html={body_html}
            htmlStyles={topicStyles}
            onLinkPress={(evt, href) => console.log(href)} />

it tells

Warning: Failed propType: Invalid props.htmlStyles key `h1` supplied to `HTMLElement`.

i use react-native 0.24.1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants