Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
amp-react-components
Advanced tools
Render AMP components with React.
className
prop.className
prop to class
prop of AMP elements for supporting HTML class attribute. Now React does't support custom element attributes, so the <amp-img className="img" />
will be rendered as <amp-img classname="img" />
type=application/json
to support AMP components, such as amp-animation and amp-bindnpm i amp-react-components
// import from package entry point
const amp = require('amp-react-components')
<amp.AmpImg {...props} />
<amp.AmpLightbox {...props} />
// only import specific component
const AmpLightbox = require('amp-react-components/lib/components/AmpLightbox')
<AmpLightbox {...props} />
// import from package entry point
import { AmpImg, AmpLightbox } from 'amp-react-components'
<AmpImg {...props} />
<AmpLightbox {...props} />
// only import specific component
import AspectRatioImg from 'amp-react-components/es/components/AmpLightbox'
<AmpLightbox {...props} />
// style.css
.img {
position: relative;
border-radius: 8px;
border: solid 1px #e0e4e9;
box-sizing: border-box;
> img {
border-radius: 8px;
}
}
// index.js
import { AmpImg } from 'amp-react-components'
import styles from './style.css'
function Compoment({...}) {
return (
<AmpImg
className ={styles.img}
src={image}
width="1"
height="1"
layout="responsive"
/>
)
}
import styled from 'styled-components'
import { AmpImg } from 'amp-react-components'
const StyledAmpImg = styled(AmpImg)`
position: relative;
border-radius: 8px;
border: solid 1px #e0e4e9;
box-sizing: border-box;
> img {
border-radius: 8px;
}
`
function Compoment({...}) {
return (
<StyledAmpImg
src={image}
width="1"
height="1"
layout="responsive"
/>
)
}
AmpState
) with Script Tagimport { AmpImg, AmpState } from 'amp-react-components'
function Compoment({...}) {
const id = "myAnimals"
const state = {
"dog": {
"imageUrl": "/img/dog.jpg",
"style": "greenBackground"
},
"cat": {
"imageUrl": "/img/cat.jpg",
"style": "redBackground"
}
}
return (
<>
<AmpState id={id} state={state} />
<p data-amp-bind-text="'This is a ' + currentAnimal + '.'">This is a dog.</p>
<p class="greenBackground" data-amp-bind-class="myAnimals[currentAnimal].style">
Each animal has a different background color.
</p>
<AmpImg width="300" height="200" src="/img/dog.jpg" data-amp-bind-src="myAnimals[currentAnimal].imageUrl" />
<button on="tap:AMP.setState({currentAnimal: 'cat'})">Set to Cat</button>
</>
)
}
import { ampSetState } from 'amp-react-components/utils'
function Button(){
const state = {
foo: 'bar'
}
return (
<button
on=`tap:${ampSetState(state)}`
>
click me
</button>
)
}
<small>1.5.3 (2019-10-21)</small>
FAQs
Render AMP components with React
The npm package amp-react-components receives a total of 16 weekly downloads. As such, amp-react-components popularity was classified as not popular.
We found that amp-react-components demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.