All Projects → baruchvlz → Resq

baruchvlz / Resq

Licence: mit
React Element Selector Query (RESQ) - Query React components and children by component name or HTML selector

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Resq

Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+752.81%)
Mutual labels:  query, selector
selector
JSON Selector - fast and easy to use JSON selector
Stars: ✭ 74 (-16.85%)
Mutual labels:  query, selector
Eloquentfilter
An Eloquent Way To Filter Laravel Models And Their Relationships
Stars: ✭ 1,113 (+1150.56%)
Mutual labels:  query
Autocomplete
🔮 Fast and full-featured autocomplete library
Stars: ✭ 1,268 (+1324.72%)
Mutual labels:  query
Queryql
Easily add filtering, sorting, and pagination to your Node.js REST API through your old friend: the query string!
Stars: ✭ 76 (-14.61%)
Mutual labels:  query
Graphql Ld.js
Linked Data Querying with GraphQL
Stars: ✭ 65 (-26.97%)
Mutual labels:  query
Pumpkindb
Immutable Ordered Key-Value Database Engine
Stars: ✭ 1,219 (+1269.66%)
Mutual labels:  query
Rumble
⛈️ Rumble 1.11.0 "Banyan Tree"🌳 for Apache Spark | Run queries on your large-scale, messy JSON-like data (JSON, text, CSV, Parquet, ROOT, AVRO, SVM...) | No install required (just a jar to download) | Declarative Machine Learning and more
Stars: ✭ 58 (-34.83%)
Mutual labels:  query
Async Gamequery Lib
A high-performance java game query library designed for steam/source based games and others
Stars: ✭ 88 (-1.12%)
Mutual labels:  query
Postcss Prefix Selector
Prefix all CSS rules with a selector
Stars: ✭ 75 (-15.73%)
Mutual labels:  selector
Hpq
Utility to parse and query HTML into an object shape
Stars: ✭ 82 (-7.87%)
Mutual labels:  query
Discordgsm
📺 Monitor your game servers on Discord and tracks the live data of your game servers. Also support one-click deployment to Heroku, self-hosted. Invite: https://discordgsm.com/invite
Stars: ✭ 74 (-16.85%)
Mutual labels:  query
Js Jsonq
A simple Javascript Library to Query over Json Data
Stars: ✭ 67 (-24.72%)
Mutual labels:  query
Askxml
Run SQL statements on XML documents
Stars: ✭ 79 (-11.24%)
Mutual labels:  query
Pypika
PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.
Stars: ✭ 1,111 (+1148.31%)
Mutual labels:  query
Statebutton
一个可以用代码设置selector背景(按下去背景颜色更改,样式变化等等)的button, 再也不用写selector了
Stars: ✭ 1,276 (+1333.71%)
Mutual labels:  selector
React Native Modal Dropdown
A react-native dropdown/picker/selector component for both Android & iOS.
Stars: ✭ 1,103 (+1139.33%)
Mutual labels:  selector
Purescript Selda
A type-safe, high-level SQL library for PureScript
Stars: ✭ 72 (-19.1%)
Mutual labels:  query
Query.apex
A dynamic SOQL and SOSL query builder on Salesforce.com platform
Stars: ✭ 78 (-12.36%)
Mutual labels:  query
Astq
Abstract Syntax Tree (AST) Query Engine
Stars: ✭ 89 (+0%)
Mutual labels:  query

resq (React Element Selector Query) npm Build Status codecov

Requirements

  • React v16 or higher
  • Node 8 or higher
  • React DevTools (optional)

This library tries to implement something similar to querySelector and querySelectorAll, but through the React VirtualDOM. You can query for React composite elements or HTML elements. It provides two functions resq$ and resq$$ for selecting one or multiple components, respectively.

Installation

$ npm install --save resq

$ yarn add resq

Usage

To get the most out of the library, we recommend you use React Dev Tools to verify the component names you want to select. Granted for basic usage you don't need this as long as you know the component name beforehand, but for Styled components and MaterialUI components it will be of great help.

Type definition

interface RESQNode {
    name: 'MyComponent',
    node: HTMLElement | null,
    isFragment: boolean,
    state: string | boolean | any[] | {},
    props: {},
    children: RESQNode[]
}

resq$(selector: string, element?: HTMLElement): RESQNode
resq$$(selector: string, element?: HTMLElement): Array<RESQNode>

Basic Usage

Take this React App:

// imports

const MyComponent = () => (
    <div>My Component</div>
)

const App = () => (
    <div><MyComponent /></div>
)

ReactDOM.render(<App />, document.getElementById('root'))

Selecting MyComponent:

import { resq$ } from 'resq'

const root = document.getElementById('root');
resq$('MyComponent', root);
/*
{
    name: 'MyComponent',
    node: <div />,
    isFragment: false,
    state: {},
    props: {},
    children: []
}
*/

Wildcard selection

You can select your components by partial name use a wildcard selectors:

// imports

const MyComponent = () => (
    <div>My Component</div>
)

const MyAnotherComponent = () => (
    <div>My Another Component</div>
)

const App = () => (
    <div>
        <MyComponent />
        <MyAnotherComponent />
    </div>
)

ReactDOM.render(<App />, document.getElementById('root'))

Selecting both components by wildcard:

import { resq$$ } from 'resq'

const root = document.getElementById('root');
resq$$('My*', root);
/*
[
    {
        name: 'MyComponent',
        node: <div />,
        isFragment: false,
        state: {},
        props: {},
        children: []
    },
    {
        name: 'MyAnotherComponent',
        node: <div />,
        isFragment: false,
        state: {},
        props: {},
        children: []
    },
]
*/

Selecting MyAnotherComponent by wildcard:

import { resq$ } from 'resq'

const root = document.getElementById('root');
resq$('My*Component', root);
/*
{
    name: 'MyAnotherComponent',
    node: <div />,
    isFragment: false,
    state: {},
    props: {},
    children: []
}
*/

Async selection

Going by the same example as in basic usage, if you don't want to pass the root element to the function, you can do it this way:

import { resq$, waitToLoadReact } from 'resq'

async function getReactElement(name) {
    try {
        await waitToLoadReact(2000) // time in MS to wait before erroring

        return resq$(name)
    } catch (error) {
        console.warn('resq error', error)
    }
}

getReactElement('MyComponent')

Filtering selection

You can filter your selections byState or byProps. These are methods attached to the RESQNode return objects.

Example app:

// imports

const MyComponent = ({ someBooleanProp }) => (
    <div>My Component {someBooleanProp ? 'show this' : ''} </div>
)

const App = () => (
    <div>
        <MyComponent />
        <MyComponent someBooleanProp={true} />
    </div>
)

ReactDOM.render(<App />, document.getElementById('root'))

To select the first instance of MyComponent where someBooleanProp is true:

import { resq$ } from 'resq'

const root = document.getElementById('root')
const myComponent = resq$('MyComponent', root)
const filtered = myComponent.byProps({ someBooleanProp: true })

console.log(filtered)
/*
{
    name: 'MyComponent',
    node: <div />,
    isFragment: false,
    state: {},
    props: {
        someBooleanProp: true,
    },
    children: []
}
*/

Deep Matching with exact flag

If you are in need of filtering byProps or byState and require the filter to match exactly every property and value in the object (or nested objects), you can pass the exact flag to the function:

import { resq$ } from 'resq'

const root = document.getElementById('root')
const myComponent = resq$('MyComponent', root)
const filtered = myComponent.byProps({ someBooleanProp: true }, { exact: true })
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].