Use Anymod in a React project

Setup

To use modules with React, add the mod tag via React's render and call Anymod.render() when the React component has mounted:

class Demo extends React.Component {
  componentDidMount () {
    Anymod.render()
  }
  render () {
    // Card with top image
    return <div id="anymod-aklnr"></div>
  }
}
1
2
3
4
5
6
7
8
9

TIP

React requires you to use quotation marks (") for attributes.

You can use Anymod.render() by itself or with a callback or promise. See the section on Anymod.render for more.

Example

Rendering multiple mods

You can render multiple mods the same way as a single mod. However, React does require that its internal render function returns a single element. So to render multiple mods in a single React component, wrap them in a common element such as a <div>, like so:

render () {
  return (
    <div>
      {/* Card with top image */}
      <div id="anymod-aklnr"></div>
      {/* GitHub button */}
      <div id="anymod-oorka"></div>
      {/* Team page */}
      <div id="anymod-dmkdn"></div>    
    </div>
  )
}
1
2
3
4
5
6
7
8
9
10
11
12

Create React App

If you are using Create React App or another ESLint tool, you may encounter an error along the lines of 'Anymod' is not defined no-undef. In this case, you should add the following to the top of any files using Anymod.render():

/* global Anymod */

You can learn more about this solution here.

Re-rendering

You can call Anymod.render() as often as you'd like in your React component (or elsewhere). This method will not lead to an API call every time; if a mod has already been fetched once, Anymod.render() will use that data instead of making another API call.

TIP

See the section on Anymod.render for more.

Last Updated: 10/5/2018, 7:03:53 PM