简体   繁体   中英

How to Use amp-state in JSX?

I'm working on creating Google amp-page in a React project, and need to fetch JSON after a click.

A/C to amp.dev , i can use amp-state to fetch remote data

as

<amp-state id="shirts" [src]="'/shirts/sizesAndPrices?sku=' + selected.sku" />

How can i do the same in JSX, as writing [src] in such format leads to error

Any suggestion will be helpful. Thanks in advance

You can replace [src] with data-amp-bind-src . The latter syntax has been introduced for JSX syntax compatibility.

I don't know this is the right way, but I think, this can be a turn around If there is a better way, or if this is not recommended in any way, please comment


I needed to toggle visibility of option based on the selected option

<amp-selector
    layout="container"
    class="radio-selector"
    on="select: AMP.setState({
    selectedOption: event.targetOption,
})">
        <div option="a_show">Option A</div>
        <div option="b_show">Option B</div>
        <div option="c_show">Option C</div>
</amp-selector>
<div className="options"
    dangerouslySetInnerHTML={{
        __html: `
            <p [class]="selectedOption == 'a_show' ? 'show' : 'hide'" class="show">a</p>
            <p [class]="selectedOption == 'b_show' ? 'show' : 'hide'" class="hide">b</p>
            <p [class]="selectedOption == 'c_show' ? 'show' : 'hide'" class="hide">c</p>
        `
        }}
/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM