4.4.6 • Published 8 months ago

@phygrid/signals-react v4.4.6

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
8 months ago

@phygrid/signals-react

A React library for integrating Phygrid Signals into your react applications.

Installation

Use either yarn or npm to install the package:

# Using yarn
yarn install @phygrid/signals-react

# Using npm
npm install @phygrid/signals-react

Usage

Basic Integration

The simplest way to integrate Signals into your React application is using the useGridSignals hook:

import React, { useEffect } from 'react';
import './App.css';
import { useGridSignals } from "@phygrid/signals-react";

function App() {
  const { isReady, signalsService } = useGridSignals();
  
  useEffect(() => {
    if (isReady) {
      // Example of sending an event
      signalsService.sendEvent(...);
    }
  }, [isReady, signalsService]);

  return (
    <div className="App">
      <p>Hello Signals</p>
    </div>
  );
}

export default App;

Custom Parameters

For more control, you can initialize the signals service with custom parameters using the useGridSignalsWithExternalParams hook:

import React, { useEffect } from 'react';
import './App.css';
import { useGridSignalsWithExternalParams } from "@phygrid/signals-react";

function App() {
  const initParams = {
    "deviceId": "device-12345",
    "installationId": "install-67890",
    "spaceId": "space-abcdef",
    "tenantId": "tenant-xyz",
    "appVersion": "1.0.0",
    "appId": "com.example.app",
    "environment": "production",
    "dataResidency": "EU",
    "country": "SE",
    "installationVersion": "2.3.4",
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR...",
    "clientUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
    "ip": "192.168.1.100"
  };
  
  const { isReady, signalsService } = useGridSignalsWithExternalParams(initParams);
  
  useEffect(() => {
    if (isReady) {
      // Example of sending an event
      signalsService.sendEvent(...);
    }
  }, [isReady, signalsService]);

  return (
    <div className="App">
      <p>Hello Signals</p>
    </div>
  );
}

export default App;

API Reference

Hooks

useGridSignals()

Initializes the signals service with default parameters.

Returns:

  • isReady (boolean): Indicates whether the signals service is initialized and ready to use
  • signalsService (object): The signals service instance for sending events

useGridSignalsWithExternalParams(initParams)

Initializes the signals service with custom parameters.

Parameters:

  • initParams (object): Configuration object with the following properties:
    • deviceId (string): Unique identifier for the device
    • installationId (string): Unique identifier for the installation
    • spaceId (string): Identifier for the space
    • tenantId (string): Identifier for the tenant
    • appVersion (string): Version of the application
    • appId (string): Identifier for the application
    • environment (string): Environment (e.g., "production", "development")
    • dataResidency (string): Location for data residency
    • country (string): Country code
    • installationVersion (string): Version of the installation
    • accessToken (string): JWT or other access token
    • clientUserAgent (string): User agent string
    • ip (string): IP address

Returns:

  • isReady (boolean): Indicates whether the signals service is initialized and ready to use
  • signalsService (object): The signals service instance for sending events

Available Methods

Complete details regarding the available methods in signalsService can be found in here


Troubleshooting

If you find any errors when importing the package, make sure that 1. config-overrides.js is setup properly, an example is given below:

const webpack = require('webpack');
const path = require('path');

module.exports = function override(config, env) {
  config.module.rules.push({
    test: /\.(ts|tsx)$/,
    loader: 'ts-loader',
    options: {
      transpileOnly: true,
      compilerOptions: {
        module: 'esnext',
        moduleResolution: 'node',
      },
    },
    exclude: /node_modules/,
  });

  delete config.externals;

  config.plugins.push(
    new webpack.IgnorePlugin({ resourceRegExp: /^https-proxy-agent$/ }),
    new webpack.IgnorePlugin({ resourceRegExp: /^http-proxy-agent$/ })
  );

  config.resolve.fallback = {
    assert: require.resolve('assert/'),
    buffer: require.resolve('buffer/'),
    stream: require.resolve('stream-browserify'),
    util: require.resolve('util/'),
    net: false,
    tls: false,
    fs: false,
    child_process: false,
    http: false,
    https: false,
    os: false,
    url: false,
  };

  config.module.rules.push({
    test: /abort-controller/,
    resolve: { fullySpecified: false },
  });

  config.resolve.alias = {
    ...config.resolve.alias,
    'react': path.resolve('./node_modules/react'),
    'react-dom': path.resolve('./node_modules/react-dom')
  };

  return config;
};
  1. Make sure that your webpack.config.js is setup properly, for example:
const webpack = require('webpack');
const path = require('path');

module.exports = function override(config, env) {
  // Add React resolution alias
  config.resolve.alias = {
    ...config.resolve.alias,
    'react': path.resolve('./node_modules/react'),
    'react-dom': path.resolve('./node_modules/react-dom')
  };

  // Add externals configuration
  config.externals = {
    ...config.externals,
    react: 'React',
    'react-dom': 'ReactDOM'
  };

  // Existing fallbacks for node.js core modules
  config.resolve.fallback = {
    http: require.resolve('stream-http'),
    https: require.resolve('https-browserify'),
    stream: require.resolve('stream-browserify'),
    util: require.resolve('util/'),
    os: require.resolve('os-browserify/browser'),
    assert: require.resolve('assert/'),
    net: false,
    tls: false,
  };
  
  config.plugins.push(
    new webpack.ProvidePlugin({
      process: 'process/browser',
      Buffer: ['buffer', 'Buffer'],
    })
  );
  
  return config;
};
  1. If you are using typescript, make sure you have tsconfig.json setup properly, for example:
{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "baseUrl": "src"
  },
  "include": [
    "src"
  ]
}
  1. For react version related issues, make sure you add following in your package.json file:
{
  "resolutions": {
      "react": "^18.0.0",
      "react-dom": "^18.0.0"
    },
}
4.2.219

11 months ago

4.2.459

10 months ago

4.2.338

11 months ago

4.2.217

11 months ago

4.2.339

11 months ago

4.2.457

10 months ago

4.2.336

11 months ago

4.2.458

10 months ago

4.2.337

11 months ago

4.2.216

11 months ago

4.2.466

9 months ago

4.2.345

11 months ago

4.2.224

11 months ago

4.2.467

9 months ago

4.2.346

11 months ago

4.2.225

11 months ago

4.2.464

10 months ago

4.2.343

11 months ago

4.2.222

11 months ago

4.2.465

9 months ago

4.2.344

11 months ago

4.2.223

11 months ago

4.2.462

10 months ago

4.2.341

11 months ago

4.2.220

11 months ago

4.2.463

10 months ago

4.2.342

11 months ago

4.2.221

11 months ago

4.2.460

10 months ago

4.2.461

10 months ago

4.2.340

11 months ago

4.2.329

11 months ago

4.2.448

10 months ago

4.2.327

11 months ago

4.2.449

10 months ago

4.2.328

11 months ago

4.2.446

10 months ago

4.2.325

11 months ago

4.2.447

10 months ago

4.2.326

11 months ago

4.0.1

1 year ago

4.2.455

10 months ago

4.2.334

11 months ago

4.2.456

10 months ago

4.2.335

11 months ago

4.2.453

10 months ago

4.2.332

11 months ago

4.2.454

10 months ago

4.2.333

11 months ago

4.2.212

11 months ago

4.2.451

10 months ago

4.2.330

11 months ago

4.2.452

10 months ago

4.2.331

11 months ago

4.2.450

10 months ago

4.2.439

10 months ago

4.2.318

11 months ago

4.2.319

11 months ago

4.2.437

10 months ago

4.2.316

11 months ago

4.2.438

10 months ago

4.2.317

11 months ago

4.2.435

10 months ago

4.2.314

11 months ago

4.2.436

10 months ago

4.2.315

11 months ago

4.2.444

10 months ago

4.2.323

11 months ago

4.2.324

11 months ago

4.2.442

10 months ago

4.2.321

11 months ago

4.2.443

10 months ago

4.2.322

11 months ago

4.2.440

10 months ago

4.2.441

10 months ago

4.2.320

11 months ago

4.2.309

11 months ago

4.2.428

10 months ago

4.2.307

11 months ago

4.3.7-dev

8 months ago

4.2.429

10 months ago

4.2.308

11 months ago

4.2.426

10 months ago

4.2.305

11 months ago

4.2.427

10 months ago

4.2.306

11 months ago

4.2.424

10 months ago

4.2.303

11 months ago

4.2.425

10 months ago

4.2.304

11 months ago

4.2.433

10 months ago

4.2.312

11 months ago

4.2.313

11 months ago

4.2.431

10 months ago

4.2.310

11 months ago

4.2.432

10 months ago

4.2.311

11 months ago

4.2.430

10 months ago

4.2.419

10 months ago

4.2.417

10 months ago

4.2.418

10 months ago

4.2.415

10 months ago

4.2.416

10 months ago

4.2.413

10 months ago

4.2.414

10 months ago

4.2.301

11 months ago

4.2.423

10 months ago

4.2.302

11 months ago

4.2.420

10 months ago

4.2.300

11 months ago

4.2.408

10 months ago

4.2.409

10 months ago

4.2.406

10 months ago

4.2.407

10 months ago

4.2.404

10 months ago

4.2.405

10 months ago

4.2.402

11 months ago

4.2.403

11 months ago

4.2.411

10 months ago

4.2.412

10 months ago

4.2.410

10 months ago

4.2.401

11 months ago

4.3.6-dev

9 months ago

4.3.5-dev

9 months ago

4.4.1

8 months ago

4.4.0

8 months ago

2.0.49

1 year ago

4.4.3

8 months ago

4.4.2

8 months ago

4.4.5

8 months ago

4.4.4

8 months ago

4.4.6

8 months ago

2.0.57

1 year ago

2.0.58

1 year ago

2.0.55

1 year ago

2.0.56

1 year ago

2.0.53

1 year ago

2.0.54

1 year ago

2.0.51

1 year ago

2.0.52

1 year ago

2.0.50

1 year ago

2.0.68

1 year ago

2.0.69

1 year ago

2.0.66

1 year ago

2.0.67

1 year ago

2.0.64

1 year ago

2.0.65

1 year ago

2.0.63

1 year ago

2.0.60

1 year ago

2.0.79

1 year ago

4.3.4-dev

9 months ago

2.0.77

1 year ago

2.0.78

1 year ago

2.0.75

1 year ago

2.0.76

1 year ago

2.0.73

1 year ago

2.0.74

1 year ago

2.0.71

1 year ago

2.0.72

1 year ago

2.0.70

1 year ago

2.0.88

1 year ago

2.0.89

1 year ago

2.0.86

1 year ago

2.0.87

1 year ago

2.0.84

1 year ago

2.0.85

1 year ago

2.0.82

1 year ago

2.0.83

1 year ago

2.0.80

1 year ago

2.0.81

1 year ago

2.0.99

1 year ago

2.0.97

1 year ago

2.0.98

1 year ago

2.0.95

1 year ago

2.0.96

1 year ago

2.0.93

1 year ago

2.0.94

1 year ago

2.0.91

1 year ago

2.0.92

1 year ago

2.0.90

1 year ago

4.3.3-dev

9 months ago

4.3.2-dev

9 months ago

2.0.151

1 year ago

2.0.150

1 year ago

2.0.139

1 year ago

2.0.138

1 year ago

2.0.137

1 year ago

2.0.136

1 year ago

2.0.135

1 year ago

2.0.134

1 year ago

2.0.133

1 year ago

2.0.132

1 year ago

2.0.131

1 year ago

2.0.130

1 year ago

4.2.293

11 months ago

4.2.294

11 months ago

4.2.291

11 months ago

4.2.292

11 months ago

2.0.149

1 year ago

2.0.148

1 year ago

4.2.290

11 months ago

2.0.147

1 year ago

2.0.146

1 year ago

2.0.145

1 year ago

2.0.144

1 year ago

2.0.143

1 year ago

4.2.299

11 months ago

2.0.142

1 year ago

2.0.141

1 year ago

4.2.297

11 months ago

2.0.140

1 year ago

4.2.298

11 months ago

4.2.295

11 months ago

4.2.296

11 months ago

4.3.9-dev

8 months ago

4.3.0-dev

8 months ago

2.0.109

1 year ago

4.2.282

11 months ago

2.0.119

1 year ago

4.2.283

11 months ago

2.0.118

1 year ago

4.2.280

11 months ago

2.0.117

1 year ago

4.2.281

11 months ago

2.0.116

1 year ago

2.0.115

1 year ago

2.0.114

1 year ago

2.0.113

1 year ago

2.0.112

1 year ago

2.0.111

1 year ago

2.0.110

1 year ago

4.2.288

11 months ago

4.2.289

11 months ago

4.2.286

11 months ago

4.2.287

11 months ago

4.2.284

11 months ago

4.2.285

11 months ago

4.2.392

11 months ago

4.2.271

11 months ago

4.2.393

11 months ago

4.2.272

11 months ago

2.0.129

1 year ago

4.2.390

11 months ago

2.0.128

1 year ago

4.2.391

11 months ago

4.2.270

11 months ago

2.0.127

1 year ago

2.0.126

1 year ago

2.0.125

1 year ago

2.0.124

1 year ago

2.0.123

1 year ago

4.2.279

11 months ago

2.0.122

1 year ago

2.0.121

1 year ago

4.2.398

11 months ago

4.2.277

11 months ago

2.0.120

1 year ago

4.2.399

11 months ago

4.2.278

11 months ago

4.2.396

11 months ago

4.2.275

11 months ago

4.2.397

11 months ago

4.2.276

11 months ago

4.2.394

11 months ago

4.2.273

11 months ago

4.2.395

11 months ago

4.2.274

11 months ago

4.2.259

11 months ago

4.2.381

11 months ago

4.2.260

11 months ago

4.2.261

11 months ago

4.2.380

11 months ago

4.2.389

11 months ago

4.2.268

11 months ago

4.2.269

11 months ago

4.2.387

11 months ago

4.2.266

11 months ago

4.2.388

11 months ago

4.2.267

11 months ago

4.2.264

11 months ago

4.2.386

11 months ago

4.2.265

11 months ago

4.2.383

11 months ago

4.2.262

11 months ago

4.2.263

11 months ago

4.2.248

11 months ago

4.2.249

11 months ago

2.0.108

1 year ago

4.2.371

11 months ago

4.2.250

11 months ago

2.0.107

1 year ago

2.0.106

1 year ago

2.0.105

1 year ago

2.0.104

1 year ago

2.0.103

1 year ago

2.0.102

1 year ago

2.0.101

1 year ago

4.2.257

11 months ago

2.0.100

1 year ago

4.2.379

11 months ago

4.2.258

11 months ago

4.2.255

11 months ago

4.2.256

11 months ago

4.2.253

11 months ago

4.2.254

11 months ago

4.2.372

11 months ago

4.2.251

11 months ago

4.2.252

11 months ago

4.2.239

11 months ago

4.2.358

11 months ago

4.2.237

11 months ago

4.2.359

11 months ago

4.2.238

11 months ago

4.3.8-dev

8 months ago

4.2.360

11 months ago

4.2.246

11 months ago

4.2.247

11 months ago

4.2.244

11 months ago

4.2.245

11 months ago

4.2.363

11 months ago

4.2.242

11 months ago

4.2.364

11 months ago

4.2.243

11 months ago

4.2.361

11 months ago

4.2.240

11 months ago

4.2.362

11 months ago

4.2.241

11 months ago

4.2.349

11 months ago

4.2.228

11 months ago

4.2.229

11 months ago

4.2.468

9 months ago

4.2.347

11 months ago

4.2.226

11 months ago

4.2.469

9 months ago

4.2.348

11 months ago

4.2.227

11 months ago

4.2.470

8 months ago

4.2.356

11 months ago

4.2.235

11 months ago

4.2.357

11 months ago

4.2.236

11 months ago

4.2.354

11 months ago

4.2.233

11 months ago

4.2.355

11 months ago

4.2.234

11 months ago

4.2.473

8 months ago

4.2.352

11 months ago

4.2.231

11 months ago

4.2.353

11 months ago

4.2.232

11 months ago

4.2.471

8 months ago

4.2.350

11 months ago

4.2.472

8 months ago

4.2.351

11 months ago

4.2.230

11 months ago

2.0.48

1 year ago

2.0.47

1 year ago

2.0.46

1 year ago

2.0.45

1 year ago

2.0.44

1 year ago

2.0.42

1 year ago

2.0.41

1 year ago

2.0.40

2 years ago

2.0.39

2 years ago

2.0.38

2 years ago

2.0.37

2 years ago

2.0.36

2 years ago

2.0.35

2 years ago

2.0.34

2 years ago

2.0.33

2 years ago

2.0.32

2 years ago

2.0.31

2 years ago

2.0.30

2 years ago

2.0.29

2 years ago

2.0.28

2 years ago

2.0.27

2 years ago

2.0.26

2 years ago

2.0.24

2 years ago

2.0.7

2 years ago

2.0.3

2 years ago

2.0.0

2 years ago

1.0.0

2 years ago

0.2.0

2 years ago

0.1.18

2 years ago

0.1.16

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago