
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
craft-react
Advanced tools
Bind your react component props to Craft's element api
npm i --save craft-react
Since we are using redux to manage our store we need to configure the provider on our top level component
import { configureStore } from 'craft-react'
import { syncReduxAndRouter } from 'redux-simple-router'
import createBrowserHistory from 'history/lib/createBrowserHistory'
import { Router } from 'react-router'
import Post from './components/Post'
import PostList from './components/PostList'
const store = configureStore()
const history = createBrowserHistory()
syncReduxAndRouter(history, store)
const routes = (
<Route path='/' component='PostList'>
<Route path='/post/:slug' component='Post'>
)
ReactDOM.render((
<Provider store={ store }>
<Router
history={history}
routes={routes}
/>
</Provider>
), rootNode)
For an craft element api configured as
'api/post/<slug:{slug}>' => function($slug) {
return [
'criteria' => [
'section' => 'profile',
'slug' => $slug
],
'first' => true,
'transformer' => function(EntryModel $entry) {
return [
'slug' => $entry->slug,
'title' => $entry->title,
'postDate' => $entry->postDate,
'content' => $entry->content,
];
},
];
}
At a front-end endpoint of mysupercoolblog.com/post/a-post-slug
import React, { Component } from 'react';
import loadContent from 'craft-react'
class Post extends Component {
constructor(props) {
super(props)
}
render() {
return (
<h1>{ this.props.title }</h1>
<span className="date">{ this.props.postDate }</h1>
<p>{ this.props.content }</p>
)
}
}
export default loadContent()(Post)
If the craft endpoints don't align with the front-end endpoints the contentType
and the slug
can be passed to the loadContent
method
import React, { Component } from 'react';
import loadContent from 'craft-react'
class Post extends Component {
constructor(props) {
super(props)
}
render() {
return (
<h1>{ this.props.title }</h1>
<span className="date">{ this.props.postDate }</h1>
<p>{ this.props.content }</p>
)
}
}
export default loadContent('post', 'a-post-slug')(Post)
import React, { Component } from 'react';
import loadContent from 'craft-react'
class PostList extends Component {
constructor(props) {
super(props)
}
render() {
return posts = this.props.posts.map((post) => {
return <li>post.title</li>
})
return (
<ul>
{ posts }
</ul>
)
}
}
export default loadContent({ contentType: 'post', mapToProp: 'posts' }, null, true)(PostList)
pagination example coming soon...
loadContent([contentType || {contentType: 'type', mapToProps: 'propName'}], [slug], [isMultiple])(MyComponent)
FAQs
connect craft with element api to your react components with a redux store
The npm package craft-react receives a total of 1 weekly downloads. As such, craft-react popularity was classified as not popular.
We found that craft-react 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.