Hi! I wanted to get data to my site on React through the API, did everything as stated in the documentation, completed the installation of npm install --save woocommerce-api , created an object with the parameters as in the http://woocommerce.imtqy.com/woocommerce documentation -rest-api-docs /? javascript # pagination

 import React, { Component } from 'react'; import '../App.css'; import WooCommerceAPI from 'woocommerce-api'; class Goods extends Component { WooCommerce = new WooCommerceAPI({ url: 'http://portland.com/wp/', // Your store URL consumerKey: 'ck_c221d7f97defb2d3a045730b8a0ff470327180a6', // Your consumer key consumerSecret: 'cs_33cdde6ad3a4583624478504b86ee8fd7844b394', // Your consumer secret wpAPI: true, // Enable the WP REST API integration version: 'wc/v2' // WooCommerce WP REST API version }); render() { return( <div className="GoodsMain"> <div className="Goods"> <img src="/images/photo.png" alt="appletv"/><br/> <div className="TextAlign"> <span className="NameOfGood">{WooCommerce.get('products/1').name}</span><br/> <span className="StyleOfGood">black</span><br/> <span className="PriceOfGood">$49.99</span> </div> </div> </div> ); } } export default Goods; 

But I’m getting Line 20: 'WooCommerce' is not defined no-undef You can show how to use the WooComerce API correctly in React.

  • var WooCommerce = new WooCommerceAPI (... - KAGG Design
  • Thanks, but as it turned out, you need to connect the plugin to the Back-end and transfer data to React. "React is the front-end, the WooCommerce API is the backend. Use the API in node.js or PHP or Ruby. Then in your React app, you can now learn to write node.js :) - Oleksandr Tatarinov

0