Riot: Problem passing state data to js function in template

Created on 5 Jun 2020  ·  3Comments  ·  Source: riot/riot

Help us to manage our issues by answering the following:

  1. Describe your issue:

Hi there, I'm trying to do something which seems like it should be very straightforward. I'm attempting to pass some data to a javascript function in a riot template as below. In the Riot documentation it is stated that:

All template expressions are “just JavaScript™️”: <pre>{ JSON.stringify(props) }</pre>

So I am expecting that the below should function correctly as it is valid javascript.

<date-test>

  <p>Test date string: { state.test }</p>
  <p>Test transformed literal date string: { (new Date('2006-09-16T00:00:00Z')).toLocaleDateString() }</p>
  <p>Test transformed date string: { (new Date(state.test)).toLocaleDateString() }</p>

  <script>
    export default {
      state: {
        test: '2006-09-16T00:00:00Z'
      }
    }
  </script>

</date-test>

The first two <p> tags are rendered correctly but with the last one I'm encountering the following error reported in Chrome dev console

Uncaught (in promise) ReferenceError: state is not defined

Please note that I am not experienced in javascript - I write python, c/c++ for my day job - so it's possible that I'm doing something which is clearly wrong... Any guidance as to the correct way to do this would be much appreciated.

  1. Can you reproduce the issue?

    Post the link using one of our bug report templates:

  2. On which browser/OS does the issue appear?
    Ubuntu 20.04
    Chromium Version 83.0.4103.61 (Official Build) snap (64-bit)

  3. Which version of Riot does it affect?
    Riot.js 4.0.5

  4. How would you tag this issue?

    • [x] Question
    • [x] Bug (maybe...not sure...)
    • [ ] Discussion
    • [ ] Feature request
    • [ ] Tip
    • [ ] Enhancement
    • [ ] Performance
bug fixed

Most helpful comment

It's a compiler bug, I will check it asap

All 3 comments

It's a compiler bug, I will check it asap

Fixed in Riot.[email protected]

Excellent. All working as expected. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShiMeiWo picture ShiMeiWo  ·  3Comments

vogloblinsky picture vogloblinsky  ·  3Comments

bufferUnderrun picture bufferUnderrun  ·  3Comments

nodefish picture nodefish  ·  3Comments

samhstn picture samhstn  ·  3Comments