stencil icon indicating copy to clipboard operation
stencil copied to clipboard

Documentation typo on template map function usage

Open ilkkanisula opened this issue 9 years ago • 5 comments

Resources: Before submitting an issue, please consult our docs.

Stencil version: (run npm list @stencil/core from a terminal/cmd prompt and paste output below):

https://stenciljs.com/docs/templating

I'm submitting a ... (check one with "x") [x] bug report [ ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior: Inner curly brackets should be just bracket. This doesn't produce any error messages and array is not rendered.

Expected behavior: Error should be printed from compiler. Documentation should also be fixed.

Steps to reproduce: Follow instructions from web page.

Related code:

render() {
  return (
    <div>
      {this.todos.map( todo => {
        <div>
          <div>{todo.taskName}</div>
          <div>{todo.isCompleted}</div>
        </div>
      })}
    </div>
  )
}

Other information:

ilkkanisula avatar Sep 14 '17 05:09 ilkkanisula

@ilkkanisula Can hardly spot what's wrong here.

motss avatar Sep 14 '17 08:09 motss

Hey, thanks for opening an issue with us. Maybe im not following correctly, but that bit of code is correct. Am i looking at something wrong here?

jgw96 avatar Sep 14 '17 15:09 jgw96

@ilkkanisula @jgw96

I think I got the curly braces you meant there. Use brackets right after the fat arrow => () instead of => {}

/** The following should be the correct one */
...
return (
  <div>
    {
      this.todos.map((todo) => ( /** Not curly braces */
        <div>
          <div>{todo.taskName}</div>
          <div>{todo.isCompleted}</div>
        </div>
      )) /** Not curly braces */
    }
  </div>
);
...

motss avatar Sep 14 '17 15:09 motss

it works with curly braces if you add a return

LloydVincent avatar Sep 19 '17 07:09 LloydVincent

Hello all! Just fixed this confusion with https://github.com/ionic-team/stencil-site/commit/e06f59a2592e41616a3dcea1e1262f77d652b842. Thanks for using Stencil!

jgw96 avatar Sep 20 '17 20:09 jgw96